Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an XML reply document that I am having a terrible time with. I am still relatively new to XML parsing and am trying to find the best way to get the Elements and attributes I need. The reply doc is as follows:

XML
<?xml version="1.0" encoding="UTF-8"?>
<api:reply xmlns:api="http://www.website.com/api" version="1.0">
  <Session>
    <Reply type="Connection">
      <ErrorMessage />
      <ErrorCode>0</ErrorCode>
    </Reply>
    <Reply group="ADMIN" object="Object" type="GetSet">
      <Object>
        <ObjectName>Item</ObjectName>
        <ObjectDesc>Params</ObjectDesc>
        <ObjectType>Map</ObjectType>
        <SourceFile>DATA</SourceFile>
        <MapObject>ProcParams*Map</MapObject>
        <GetRoutine>GET</GetRoutine>
        <PutRoutine>PUT</PutRoutine>
        <GetSetRoutine>SET</GetSetRoutine>
        <GetNextRoutine>NEXT</GetNextRoutine>
        <MethodObject />
        <AccountDesc>GENSERVER</AccountDesc>
        <Selection />
        <Params>AdditionParams</Params>
        <MultiFlag />
        <MultiField />
      </Object>
      <Object>
        <ObjectName>Dictionary</ObjectName>
        <ObjectDesc>Object for DMS dictionary downloads</ObjectDesc>
        <ObjectType>Data</ObjectType>
        <SourceFile>OBJECTS</SourceFile>
        <MapObject>Map*Map</MapObject>
        <GetRoutine />
        <PutRoutine />
        <GetSetRoutine>SET</GetSetRoutine>
        <GetNextRoutine>NEXT</GetNextRoutine>
        <MethodObject>Object*Method</MethodObject>
        <AccountDesc>GENSERVER</AccountDesc>
        <Selection />
        <Params />
        <MultiFlag />
        <MultiField />
      </Object>
      <ErrorMessage />
      <ErrorCode>0</ErrorCode>
    </Reply>
  </Session>
</api:reply>



What I need to be able to do is differentiate between the first reply root node with Type=connection and the 2nd reply root node with the group= under the session root node and get all the Object node(s) attributes into a listbox. I have tried this with Xpath and XmlReaders etc but am able to quite get it worked out.

Any help with this will be greatly appreciated.
Posted
Updated 12-Aug-14 8:39am
v2
Comments
Sergey Alexandrovich Kryukov 12-Aug-14 15:57pm    
And what's the problem. What have you tried so far, more exactly?
You did not mentioned XmlDocument, did you try. :-)
"Do it or do not. There is no try".
—SA
jdpiper65 12-Aug-14 16:19pm    
I apologize for the lack of some details. I think it more a lack of the knowledge of the XmlReader and Xpath that are giving me the problems. I have been through many examples of the Xpath and the XmlReader and am sure at this point it is a simple misunderstanding of the Xpath query that is giving me the fits. The simplest thing I have tried is:
XDoc.Load(@"C:\ADPResponse.xml");
XmlNodeList nodes = XDoc.DocumentElement.SelectNodes("/Reply/Object");
foreach (XmlNode node in nodes)
{
lstResponse.Items.Add(node.InnerText.ToString());
}
and nothing is dropped into the listbox which is what leads down the path of my failure to properly enumerate the Root Node\Elements\attributes structure.
jdpiper65 12-Aug-14 16:59pm    
Ahh the wonders of w3schools. Getting the syntax of the Xpath queries down has helped me to figure this out on my own. I love this site as it has been a boon to my efforts building both simple and complex asp.net apps and also to learn c# coming from VB.net.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900