Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Xpath and XmlNodeList help

Avatar of jimbona27
jimbona27Flag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingC#ASP.NET
14 Comments1 Solution2162 ViewsLast Modified:
hi EE,
I have the following XML that I need to read through using XPATH.

The C# below allows me to read through the XML to get all the ID nodes out into my List.

I now need to grab the corresponding 'test' node.

My approach fails, see the commented out lines.

I need to modify the code so that I can access the following:

myArray[0]
    id = qwerty
    test = here

myArray[1]
    id = qwerty2
    test = here2

Please can I have some help here as I'm completely stuck how to get around this?!!

Many thanks!
a loop
        {
            XmlDocument xmldoc = new XmlDocument();
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmldoc.NameTable);
            nsMgr.AddNamespace("a", "http://www.w3.org/2005/Atom");
            xmldoc.LoadXml(sr.ReadToEnd());
            XmlNodeList nodeList = xmldoc.SelectNodes("/a:feed/a:entry/a:id", nsMgr);
 
            string test = (XmlNode)updatedNode.InnerText.ToString();
 
            foreach (XmlNode Xnode in nodeList)
            {
                  myList.Add(Xnode.InnerText);  // save ID node into List
                  //XmlNodeList testNode =xmldoc.SelectNodes("/a:feed/a:entry/a:test", nsMgr);
            }
        }
 
 
 
// XML 
 
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>aaa</title>
  <subtitle>bbb</subtitle>
  <updated>vvv</updated>
  <author>
    <name>fff</name>
    <uri>iii</uri>
    <email>kkk</email>
  </author>
  <id>pppp</id>
  <entry>
    <title>gggg</title>
    <link href="aa" />
    <id>qwerty</id>
    <summary></summary>
    <test>here</test>
    <content>qazxsw</content>
  </entry>
  <entry>
    <title>gggg2</title>
    <link href="aa2" />
    <id>qwerty2</id>
    <summary></summary>
    <test>here2</test>
    <content>qazxsw2</content>
  </entry>
</feed>
ASKER CERTIFIED SOLUTION
Avatar of abel
Commented:
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answers