2

I have an xml document in the below format.

<Abc xmlns="http://qusetons.com/Cdc/AbcSchema.xsd">
  <xxx>False</xxx>
  <yyy>True</yyy>
  <sss>Pd</sss>
</Abc>

I am using XDocument class to parse this document

 var doc= XDocument.Load(fullfilepath);

now the below code to get the value of node is not working. wat should i do to get this code?

doc.XPathSelectElement("/Abc/xxx").value
John Saunders
  • 160,644
  • 26
  • 247
  • 397
user2799127
  • 113
  • 2
  • 9

2 Answers2

8

Try this one

var doc = XDocument.Parse(data);  
var names = new XmlNamespaceManager(new NameTable());
names.AddNamespace("emtpy", "http://qusetons.com/Cdc/AbcSchema.xsd");
Console.WriteLine(doc.XPathSelectElement("/emtpy:Abc/emtpy:xxx", names).Value);
John Saunders
  • 160,644
  • 26
  • 247
  • 397
PratikP24
  • 493
  • 5
  • 7
  • Really this is the format i ma expecting . But while executing i am getting the below error "Namespace Manager or XsltContext needed." – user2799127 Dec 12 '13 at 05:34
  • Very fine it is working good. the issue is i havent added names as an argument. One more is how can i avoid this "/empty" with a blank string – user2799127 Dec 12 '13 at 05:42
  • This could help you to find out answer [link](http://stackoverflow.com/questions/4271689/xml-selectnodes-with-default-namespace-via-xmlnamespacemanager-not-working-as-ex) – PratikP24 Dec 12 '13 at 06:01
0
doc.Elements(XName.Get("xxx"));
Savaratkar
  • 1,974
  • 1
  • 24
  • 44