Solved

Parsing XML with XmlNodeList

Posted on 2004-10-10
5
867 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
Comment Utility
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
Comment Utility
Note that you could also specify which one you want in the SelectSingleNode parameter:
SelectSingleNode("StringOption[position()=2]").
0
 

Author Comment

by:jrmcdona
Comment Utility
Ah, that looks cleaner than my solution.

thanks!
0
 
LVL 14

Expert Comment

by:AvonWyss
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now