Showing posts with label Read XMl WIth Namespace. Show all posts
Showing posts with label Read XMl WIth Namespace. Show all posts

Thursday, July 30, 2009

Read XML which has Namespace

string strXml ="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<objects xmlns=\"http://www.fubar.net\">"+
"<description>"+
"This is the primary configuration file."+
"</description>"+
"<import resource=\"assembly://MyCoolAssm.Config/SuperDuper.xml\" />"+
"<import resource=\"./Milk.Generated.xml\" />"+
"<import resource=\"./Sugar.Generated.xml\" />"+
"</objects>";

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(strXml);

XmlNamespaceManager xMan = new XmlNamespaceManager(xDoc.NameTable);
xMan.AddNamespace("myNs", "http://www.fubar.net");
XmlNodeList xnList = xDoc.SelectNodes("/myNs:objects/myNs:import",xMan);
int countNode = xnList.Count;