现在的位置: 首页 > 综合 > 正文

XML遭遇缺省Namespace

2012年11月03日 ⁄ 综合 ⁄ 共 511字 ⁄ 字号 评论关闭
缺省命名空间也要定义名字,并使用它。
 
    Log.ShowMsg("Load {0}",dataFile);
    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load(dataFile);
 
    XmlNamespaceManager nm=new XmlNamespaceManager(xmlDoc.NameTable);
    nm.AddNamespace("c","http://tempuri.org/Cingular Service Plan.xsd");
 
    XmlElement rootNode=xmlDoc.DocumentElement;
    XmlNodeList list=rootNode.SelectNodes("/c:CINGULAR/c:CINGULARCATALOG/c:CATALOG/c:NATIONS",nm);
    Console.WriteLine("Count:"+list.Count.ToString());

抱歉!评论已关闭.