我知道以前曾以类似的方式提出过这个问题,但我似乎无法解决这个问题。
我有一些xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Research xmlns="http://www.rixml.org/2005/3/RIXML" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" createDateTime="2011-03-29T15:41:48Z" language="eng" researchID="MusiJvs3008">
<Product productID="MusiJvs3008">
<StatusInfo currentStatusIndicator="Yes" statusDateTime="2011-03-29T15:41:48Z" statusType="Published" />
<Source>
<Organization type="SellSideFirm" primaryIndicator="Yes">
<OrganizationID idType="Reuters">9999</OrganizationID>
我正在尝试使用 xpath 读取值:
XPathDocument xmldoc = new XPathDocument(xmlFile);
XPathNavigator nav = xmldoc.CreateNavigator();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable);
nsMgr.AddNamespace(string.Empty, "http://www.rixml.org/2005/3/RIXML");
XPathNavigator result = nav.SelectSingleNode("/Research", nsMgr); // <-- Returns null!
但即使是对根节点的简单选择也会返回 null!我确定我的命名空间有问题。有人可以帮忙吗?
理想情况下,我想要简单的线条,让我从 xml 文件中选择值,即
String a = xmlDoc.SelectSingleNode(@"/Research/Product/Content/Title").Value;
顺便说一句,我没有(直接)控制 XML 文件内容。