?
Solved

Parsing XML with XmlNodeList

Posted on 2004-10-10
5
Medium Priority
?
881 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 1500 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: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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