I am trying to get Absoluteentry tag's value from the below xml string, but its displaying objectrefrence not set exception
<?xml version="1.0" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<AddResponse xmlns="http://www.sap.com/SBO/DIS">
<PickListParams>
<Absoluteentry>120072</Absoluteentry>
</PickListParams>
</AddResponse>
</env:Body>
</env:Envelope>
Code
XDocument doc = XDocument.Parse(xmlstring);
doc.Element("Envelope").Element("Body").Element("AddResponse").Element("PickListParams").Element("Absoluteentry").Value;
You can use
Descendants
too.Descendants
finds children at any level.Look at the XML:
That's the
Envelope
element in the namespace with URI"http://www.w3.org/2003/05/soap-envelope"
.Now look at your code:
That's looking for an
Envelope
element that's not in any namespace. You should specify the namespace - and the namespaces of the other elements you're looking for: