Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parsing XML with XmlNodeList

Posted on 2004-10-10
5
Medium Priority
?
885 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
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
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 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