다음과 같은 내용이있는 XML 문서가 있습니다.
<CHandlingDataMgr>
<HandlingData>
<Item type="CHandlingData">
<handlingName>AIRTUG</handlingName>
<fMass value="1400.000000" />
<fSteeringLock value="30.000000" />
<SubHandlingData>
<Item type="NULL" />
<Item type="NULL" />
<Item type="NULL" />
</SubHandlingData>
</Item>
<Item type="CHandlingData">
<handlingName>ADDER</handlingName>
<fMass value="1800.000000" />
<fSteeringLock value="42.000000" />
<SubHandlingData>
<Item type="CCarHandlingData">
<fBackEndPopUpCarImpulseMult value="0.075000" />
<fBackEndPopUpBuildingImpulseMult value="0.030000" />
<fBackEndPopUpMaxDeltaSpeed value="0.250000" />
</Item>
<Item type="NULL" />
<Item type="NULL" />
</SubHandlingData>
</Item>
</HandlingData>
</<CHandlingDataMgr>
모든 "fMass"태그의 값을 25 % 줄이고 모든 "fSteeringlock"값의 값을 50 % 줄이려면 어떻게해야합니까? 어떤 도구를 사용해야합니까?
C # XML Linq 사용해보기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication37
{
class Program
{
const string FILENAME = @"\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<XElement> Items = doc.Descendants("Item").ToList();
XAttribute value = null;
foreach (XElement item in Items)
{
XElement fMass = item.Element("fMass");
if (fMass != null)
{
value = item.Element("fMass").Attribute("value");
fMass.Value = (0.75 * ((double)value)).ToString();
}
XElement fSteeringLock = item.Element("fSteeringLock");
if (fSteeringLock != null)
{
value = item.Element("fSteeringLock").Attribute("value");
fSteeringLock.Value = (0.5 * ((double)value)).ToString();
}
}
doc.Save(FILENAME);
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다