XMLReader or XMLDocument ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I read the attributes of this XML? I have a page with text boxes that
i want to read
these values in. notice there are 2 Parameter tags with the same attributes.
Code would help


<TranslationRecords>

<TranslationRecord TrxID="1">

<ParameterCollection>

<Parameter KeyName="FielDelimiterChar" KeyValue="29" />

<Parameter KeyName="SegmentDelimiterChar" KeyValue="30" />

</ParameterCollection>

</TranslationRecord>

</TranslationRecords>

Thanks
 
Hi there,

For small documents, it's the easiest to use XMLDocument.
Then, you can either read elements from it, or use XPath.

In your case, something like the following should work:

XmlDocument doc = new XmlDocument();
doc.Load(...);
XmlElement root = doc.DocumentElement; // TranslationRecords
XmlNode id = root.SelectSingleNode("TranslationRecord/@TrxID");
if (id != null)
return id.Value;

In case of multiple nodes, you can use SelectNodes and iterate the result.

Hope this helps,
Michel
 
Back
Top