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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top