嗨,这是一个巨大的文件,我需要更改元素“AccumulatorFactor”的值等于元素“Price”
示例:节点Prepaid2Prepaid中的价格为60,因此元素“AccumulatorFactor”也应为60.
<NodeCopy><Node>SC14
<Condition>ServiceClass
<Comment>SC 14 with access fees of 12500 for 30 days</Comment>
<Values>14</Values>
</Condition>
<Node>Community CUG
<Node>Prepaid2Prepaid
<Condition>BooleanOperator
<Operation>AND</Operation>
<Condition>NumberList
<Type>0</Type>
<Number>75</Number>
</Condition>
<Condition>CommunityId
<Value>1-999</Value>
</Condition>
</Condition>
<Tariff>Rate
<UnitType>Time</UnitType>
<Price>60.0
<Factor>60</Factor>
</Price>
<Interval>1
<Factor>1</Factor>
</Interval>
<UpdateType>Active</UpdateType>
<AccumulatorFactor>0.0</AccumulatorFactor>
</Tariff>
</Node>
</Node>
<Node>A2A
<Condition>NumberList
<Type>0</Type>
<Number>75</Number>
</Condition>
<Node>Price
<Tariff>Rate
<UnitType>Time</UnitType>
<Price>163.2
<Factor>60</Factor>
</Price>
<Interval>1
<Factor>1</Factor>
</Interval>
<UpdateType>Active</UpdateType>
<AccumulatorFactor>0.0</AccumulatorFactor>
</Tariff>
</Node>
</Node>
<Node>All Operators
<Condition>NumberList
<Type>0</Type>
<Number>77,78
70
76
2911,1108,1177
79
71
3,4,2
121,185,200,91,888,971,2070,890,913,189
555,809</Number>
</Condition>
<Node>Price
<Tariff>Rate
<UnitType>Time</UnitType>
<Price>178.8
<Factor>60</Factor>
</Price>
<Interval>1
<Factor>1</Factor>
</Interval>
<UpdateType>Active</UpdateType>
<AccumulatorFactor>0.0</AccumulatorFactor>
</Tariff>
</Node>
</Node>
</Node>
</NodeCopy>
答案 0 :(得分:0)
public void OverWriteXMLElement()
{
string AppFileurl = System.Web.HttpContext.Current.Server.MapPath(@"~/Config/GlobalConfig.aspx.cs.xml");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(AppFileurl);
string UserFileurl = System.Web.HttpContext.Current.Server.MapPath(@"~/Config/UserManagement.aspx.cs.xml");
XmlDocument UserDoc = new XmlDocument();
UserDoc.Load(UserFileurl);
XmlNodeList aNodes = xDoc.SelectNodes("/Application/PageSetting/Pagination");
XmlNodeList UNodes = UserDoc.SelectNodes("/UserManagement/PageSetting/Pagination");
foreach (XmlNode unode in UNodes)
{
XmlNode child1 = unode.SelectSingleNode("PageSize");
if (child1.InnerText == "" || child1.InnerText == null)
{
foreach (XmlNode node in aNodes)
{
child1.InnerText = node.SelectSingleNode("PageSize").InnerText;
UserDoc.Save(UserFileurl);
}
}
}
您可以在另一个xml文件的帮助下更改一个xml文件的xml元素。