I am reading an xml where I need the code of the received message, for this I did this in a part of the code:
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 on the if
; 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>
XmlReader
It is a sequential reader, it reads one node at a time, that is, when you find thatns2:Response
it does not yet know that there is more data inside the element, you have to keep reading, something like this: