Solved

Parsing XML with XmlNodeList

Posted on 2004-10-10
5
880 Views
Last Modified: 2008-03-17
I have this XML and I am trying to the value of the 2nd StringOption entry. (<StringOption value="56789" name="id"></StringOption>)

So I can get to the OptionList node like this:
XmlNodeList nodes = this.GetXmlDocument(strXML).SelectNodes("ListMeetingsReply/MeetingReply/OptionList");

Then I am binding a datagrid to the nodes.

I can write out the value of the first "StringOption" like this:
<%#((System.Xml.XmlNode)Container.DataItem).SelectSingleNode("StringOption").Attributes["value"].Value %>
It gives me 1234...

But since the second "StringOption" entry is named the same how would I get its value instead???

<ListMeetingsReply>
<MeetingReply>
<OptionList>
<StringOption value="1234" name="name"></StringOption>
<StringOption value="56789" name="id"></StringOption>
</OptionList>
</MeetingReply>
</ListMeetingsReply>



Urgent! Thanks for the help here....
0
Comment
Question by:jrmcdona
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:jrmcdona
ID: 12273896
I solved it.

<%#((System.Xml.XmlNode)Container.DataItem).SelectSingleNode("StringOption").NextSibling.NextSibling.Attributes["value"].Value

thanks

0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 500 total points
ID: 12274632
Note that you could also specify which one you want in the SelectSingleNode parameter:
SelectSingleNode("StringOption[position()=2]").
0
 

Author Comment

by:jrmcdona
ID: 12277831
Ah, that looks cleaner than my solution.

thanks!
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12277863
You're welcome. Note that both SelectSingleNode and SelectNodes use an XPath expression to select the node(s), and it's well worth getting to know some XPath if you're dealing with XML data. It's also the query language used for XSLT transformations.
0
 

Author Comment

by:jrmcdona
ID: 12291041
Will I be able to sort my datagrid using the XmlNodeList??

Basically, i think i will somehow need to load the XmlNodeList into a dataview.

I posted this question here if you would like to get some points!


http://experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21165490.html

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question