user2799127
user2799127

Reputation: 113

How to Select an XML Node with a Namespace in LINQ to XML

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

Upvotes: 2

Views: 3035

Answers (2)

PratikP24
PratikP24

Reputation: 493

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);

Upvotes: 8

Savaratkar
Savaratkar

Reputation: 2084

doc.Elements(XName.Get("xxx"));

Upvotes: 0

Related Questions