I have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<createTransactionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<messages>
<resultCode>Ok</resultCode>
<message>
<code>I00001</code>
<text>Successful.</text>
</message>
</messages>
<transactionResponse>
<responseCode>1</responseCode>
<authCode>25C10X</authCode>
<messages>
<message>
<code>1</code>
<description>This transaction has been approved.</description>
</message>
</messages>
</transactionResponse>
</createTransactionResponse>
What is the easiest way to get success. from createTransactionResponse->messages->message->text?
Here is my code:
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("anet", "AnetApi/xml/v1/schema/AnetApiSchema.xsd");
var myNodes = doc.SelectNodes("//anet:messages", nsmgr);
myNodes returns 2 nodes. Internal xml node [0]:
<resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Ok</resultCode><message xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<code>I00001</code>
<text>Successful.</text>
</message>
Internal xml node [1]:
<message xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<code>1</code>
<description>This transaction has been approved.</description>
</message>
My problem is that I cannot go deeper.
//anet:messages/messagegives nothing.
//anet:createTransactionResponse/messagesgives nothing.
I'm just trying to get specific element values, such as "I00001" and "25C10X."
What am I doing wrong?
source
share