Monday, 16 February 2015

how to parse xml , linq c#



i am trying to load the xml file as below and read the value for each element but the Result count always = Zero , below my xml example with code


1 ) My xml is :



<ROOT xmlns="authenticateUser">
<PARTYCODE></PARTYCODE>
<VRETCODE>10</VRETCODE>
<PRETCODE>10</PRETCODE>
<VRETERR>Incorrect user name or password entered.</VRETERR>
</ROOT>


2 ) My Code is :



XDocument Doc = XDocument.Parse(strFileData);
var Result = (from Root in Doc.Descendants("ROOT")
select new
{
PARTYCODE = Root.Element("PARTYCODE").Value ?? string.Empty,
VRETCODE = Root.Element("VRETCODE").Value ?? string.Empty,
PRETCODE = Root.Element("PRETCODE").Value ?? string.Empty,
VRETERR = Root.Element("VRETERR").Value ?? string.Empty,
}).ToList();

No comments:

Post a Comment