Does not show the value of an XMl node

2

I am reading an xml where I need the code of the received message, for this I did in one part of the code this:

 string responseValue;
  while (reader.Read())
    {
     if (reader.Name == "ns2:Response")
        {
          if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
           {
              responseValue = reader.Value;
            }
         }
    }

when I put a breakpoint in the if ; It does not show any value. Why can this happen?

The xml is like this (or the part where I want to get the value):

<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-14799">
  <ns2:SendInvoice xmlns:ns2="http://www.zadrwan.com/services/" xmlns:ns3="http://www.zadrwan.com/services/DocumentSendTo" xmlns:ns4="http://www.zadrwan.com/services/VersionRequest">
      <ns2:Response>200</ns2:Response>
      <ns2:Comments>Ejemplar recibido exitosamente pasará a verificación. </ns2:Comments>
  </ns2:SendInvoice>
</SOAP-ENV:Body>
    
asked by ger 14.11.2018 в 16:46
source

1 answer

1

XmlReader is a sequential reader, read one node at a time, that is when you find ns2:Response do not know yet that there is more data within the element, you have to keep reading, something like this:

while (reader.Read())
{
    if (reader.Name == "ns2:Response")
    {
        while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
        {
            if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
            {
                responseValue = reader.Value;
            }
        }
    }
}
    
answered by 14.11.2018 / 17:18
source