asp.net 读取带命名空间的Xml文档

作者:袖梨 2022-06-25
 代码如下 复制代码
  StringReader textReader = new StringReader(surveyProject.SurveryContent);
             XPathDocument xd = new XPathDocument(textReader);
             XPathNavigator navigator = xd.CreateNavigator();
 
               -- 加入命名空间
             NameTable nt = new NameTable();
             XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
             nsmgr.AddNamespace("rc", "http://sechemas.hirede.com/2011/05/Apps/ReferenceChecking");
       
               -- 用的时候还得传入
             XPathNavigator pathNavigator = navigator.SelectSingleNode("//rc:BasicInformation/rc:Name", nsmgr);
 
             if (pathNavigator != null)
             {
                 return pathNavigator.Value;
            }

相关文章

精彩推荐