xmlns attribute???

  • Thread starter Thread starter John
  • Start date Start date
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.
 
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);
 
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);
 
Back
Top