0

I am trying to parse some data out of a response to a SOAP request using C#. The response has the a Soap Envelope and the Soap Body contains the response from the system. The response includes a header and then a bunch of repeated blocks of XML information from the original request. The request was to get the status of a list of tasks, and the response lists each task, the status and some other information. Here is a mock-ed up sample.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
  <GetTaskStatusResponse xmlns="http://tasktracker.com/2011">
     <ResponseHead>
        <ResponseId>345234523452346</ResponseId>            
        <Timestamp>2014-11-05T09:23:51-06:00</Timestamp>
     </ResponseHead>         
        <TaskStatusList>
           <TaskStatus>
              <TaskId>20141155448</AckId>
              <FilingId>672</FilingId>
              <Status>COMPLETE</Status>
        </TaskStatus>
         <TaskStatus>
              <TaskId>20141135448</AckId>
              <FilingId>673</FilingId>
               <Status>COMPLETE</Status>
        </TaskStatus>
        <TaskStatus>
              <TaskId>20141154878</AckId>
              <FilingId>674</FilingId>
               <Status>ERROR</Status>
                <ErrorList>
                    <Error>34-5</Error>
                    <Error>34-6</Error>
                    <Error>77-8</Error>
                </ErrorList>
            </TaskStatus>
        <TaskStatus>
              <TaskId>20154448</AckId>
              <FilingId>675</FilingId>
               <Status>COMPLETE</Status>
        </TaskStatus>
     </TaskStatusList>

.... ....

So far I've been able to load the file and add in the first namespace for soapevn to the Namespace Manager

nm.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");

When I try and Select a single node, this works:

XmlNode node = xml.SelectSingleNode("/soapenv:Envelope/soapenv:Body", nm);

But when I try to dive deeper I get no node found.

  XmlNode node = xml.SelectSingleNode(
        "/soapenv:Envelope/soapenv:Body/GetTaskStatusResponse/", nm);
            if (node == null)
            {
                Console.WriteLine("No node found.");
            }
            else
            {
                Console.WriteLine("Found Node");
                Console.WriteLine(node.Value);
                Console.WriteLine(node.InnerText);

I am assuming that it is because of this element:

<GetSubmissionStatusResponse xmlns="http://tasktracker.com/2011">

I tried adding an entry with "" or empty.String with the associated Uri (http://tasktracker.com/2011) to the namespace manager object, I does not resolve my issue. My ultimate goal will be to parse the repeating task list and dump those details into a table. So once I get passed this roadblock, I believe I will need to figure out how to loop through blocks of repeated nodes.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
smk081
  • 783
  • 1
  • 10
  • 36
  • Yes, `xmlns="http:....` redefines "default namespace' for that/child nodes. Precise explanation is in [this answer](http://stackoverflow.com/a/2911160/477420) from linked duplicate. – Alexei Levenkov Nov 06 '14 at 18:40
  • I've tried the solution reference here, by adding in a blank namespace prefix with the URI in the data but have not been successful. – smk081 Nov 06 '14 at 22:11
  • "blank namespace prefix with the URI"???? What do you mean "blank"? (Consider updating your post with code that does not work so it can be voted to re-open). – Alexei Levenkov Nov 06 '14 at 22:46

0 Answers0