reading XML file?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

If I have an XML document, how can I find out what the contents of a certain
tag is?

For example, if I have this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>

How can I know what the contents of the addon_low node is? Is there any way
that I can check if XmlTextReader.Name equals "addon_low", then display
3205?

Thanks.
 
I think the easist way is that you can create a C# class and serialize
the contents into an object, and check the contents of the property.

HTH.
 
Hi VMI,
you could use an XPath expression to select the node, then read the inner
text to get the addon_low node value. i.e.

string strXml = @"<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXml);

XmlNode addOnLow = xmlDoc.SelectSingleNode("/NewDataSet/Table1/addon_low");

string innerValue = addOnLow.InnerText;


Hope that helps
Mark R Dawson
http://www.markdawson.org
 
Back
Top