I receive this XML from an external source:
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1300">
<msg>Command completed successfully; no messages</msg>
</result>
<trID>
<clTRID>TEST-12345</clTRID>
<svTRID>IRNIC_2011-09-21T13:44:25+04:30_f1u</svTRID>
</trID>
</response>
</epp>
I want to extract the value of the code attribute of the result element. I used this code:
XDocument doc = XDocument.Parse(response);
XNamespace ns = "urn:ietf:params:xml:ns:epp-1.0";
string value = doc.Descendants(ns + "result").First().Attribute("code").Value;
However, it throws null value exception, because doc.Descendants(ns + "result")
is null.
What's wrong here?