0

私は System.Xml.Linq;xmlドキュメントからXpathを照合するために使用しました。XElementSaveOptions両方がから取得しSystem.Xml.Linq;ます。

           XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46");

            XElement docRfsid = XElement.Parse(content);
            //if (docRfsid.XPathSelectElement("//ns:RFSID", nsmgr).Value != null)
            if (Regex.Match(docRfsid.ToString(), "RFSID", RegexOptions.IgnoreCase).Success)
            {
                projData.RfsId = docRfsid.XPathSelectElement("//ns:RFSID", nsmgr).Value.ToString();
            }

            XElement doc_Financial = XElement.Parse(content);
            string resultFinancial = doc_Financial.XPathSelectElement("//ns:Financial", nsmgr).ToString(SaveOptions.DisableFormatting);

System.Xml.Linq;.net Framework 2.0のみを使用する必要があるため、dllを削除したいだけです。私が使用できる他の選択肢はありますかSystem.Xml.Linq;

4

2 に答える 2

1

はい。System.Xml.XmlDocumentを使用します。具体的には、その上にあるSelectNodes()メソッド、DocumentElementプロパティ、または任意のXmlElementインスタンスを使用します。このメソッドはXPathを受け入れ、一致するXmlElementsのリストを返します(ノード(XmlNode)または属性(XmlAttribute)のどちらでも)。これは古いCOMXmlDocumentオブジェクトに基づいており、フレームワークのバージョン1.1までさかのぼって使用できます。

于 2013-01-02T12:58:23.663 に答える
1

System.Xml

何かのようなもの

XmlDocument doc = new XmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46");
XmlNode financialNode = doc.DocumentElement.SelectNode("ns:Financial",nsmgr);
strring resultFinancial = null;
if (financialNode != null)
{
  resultFinancial = financialNode.InnerText;
}

ある種のこと。

于 2013-01-02T13:06:11.903 に答える