How to update xml file node value using XmlDocument

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
This is my xml

<?xml version="1.0" encoding="utf-8"?>
<TickerBrokerStandardDateLineitem>
<Ticker />
<TickerID />
<TickerBrokerStandardDateLineitemValues>
<TickerBrokerStandardDateLineitemValue>
<TabName>Consensus Model</TabName>
<StandardDate>1Q 2010</StandardDate>
<BRTab>IS</BRTab>
<BRLineItem>Revenues</BRLineItem>
<Action>Extracted</Action>
<StandardLineItem>Net Revenue</StandardLineItem>
<StandardValue>329.623</StandardValue>
</TickerBrokerStandardDateLineitemValue>
<TickerBrokerStandardDateLineitemValue>
<TabName>Consensus Model</TabName>
<StandardDate>2Q 2010</StandardDate>
<BRTab>IS</BRTab>
<BRLineItem>Revenues</BRLineItem>
<Action>Extracted</Action>
<StandardLineItem>Net Revenue</StandardLineItem>
<StandardValue>454.776</StandardValue>
</TickerBrokerStandardDateLineitemValue>
</TickerBrokerStandardDateLineitemValues>
</TickerBrokerStandardDateLineitem>

I tried to update node value this way. just compare and if value same then replace with new value

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(xmlFile);

IEnumerator ie = xmlDoc.SelectNodes("TickerBrokerStandardDateLineitem/TickerBrokerStandardDateLineitemValues/TickerBrokerStandardDateLineitemValue/StandardLineItem").GetEnumerator();

while (ie.MoveNext())
{
if ((ie.Current as XmlNode).Value.Trim().ToUpper() == olditem.Trim().ToUpper())
{
(ie.Current as XmlNode).Value = newitem;
}
}

xmlDoc.Save(xmlFile);

but (ie.Current as XmlNode).Value is getting NULL

please tell me how to update StandardLineItem if value match?

thanks

Continue reading...
 
Back
Top