私はこの質問が以前に同様の方法で尋ねられたことを知っていますが、私はこれを機能させることができないようです。
私はいくつかの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ファイルの内容を(直接)制御することはできません。