xmlns attribute???

J

John

HI,

I have a xml document containing a xmlns attribute.

xmlns="urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list">

I am using C# and statement xmlDoc.SelectNodes("//list") returns me nothing.

However, if I remove that attribute, this C# statement works.

Please help me understand this attribute.

Thanks.
 
A

Anthony Jones

John said:
HI,

I have a xml document containing a xmlns attribute.

xmlns="urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list">

I am using C# and statement xmlDoc.SelectNodes("//list") returns me nothing.

However, if I remove that attribute, this C# statement works.

Please help me understand this attribute.



You need to use the XmlNamespaceManager

XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);

nm.AddNamespace("a",
"urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list");

XmlNodeList nl = xmlDoc.SelectNodes("//a:list", nm);
 
J

John

Thank you very much.

Anthony Jones said:
You need to use the XmlNamespaceManager

XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);

nm.AddNamespace("a",
"urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list");

XmlNodeList nl = xmlDoc.SelectNodes("//a:list", nm);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top