cannot retieve node value from xml

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
I try to retrieve the "ErrMsg" element value from this xml using this code, but I get an error saying object reference not set to an instance of an object

<pre class="prettyprint <Data xmlns="
<Return>
<Qty>5</Qty>
<AdressList>
<Adress>
<Name>Luke SkyWalker</Name>
<Street>Milky Way</Street>
<PostalCode>12345</PostalCode>
<City>Earth</City>
<Qty />
</Adress>
</AdressList>
</Return>
<Error>
<ErrCode>0</ErrCode>
<ErrMsg />
</Error>
</Data>[/code]
<br/>
<pre class="prettyprint int ErrValue = 0;
string ErrMsg = string.Empty;
//int value = 0;
try
{
ErrValue = Convert.ToInt32(xdoc.Element("Error").Element("ErrMsg").Value);

if (ErrValue > 0)
{

}
}
catch (Exception ex)
{
ErrValue = 0;
}[/code]
<br/>

Can somone please show me whats wrong?






View the full article
 
Back
Top