Solved

Parsing XML with XmlNodeList

Posted on 2004-10-10
5
871 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now