سؤال

I have used System.Xml.Linq; to match Xpath from xml document. XElement and SaveOptions both get from 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);

I just want to remove System.Xml.Linq; dll since I have to use .net framework 2.0 only. Is there any other alternatives that I can use to System.Xml.Linq;.

هل كانت مفيدة؟

المحلول

Yes. Use System.Xml.XmlDocument, specifically the SelectNodes() method on it, the DocumentElement property or any XmlElement instance. This method accepts an XPath and returns a list of XmlElements that match (whether they be nodes (XmlNode) or attributes (XmlAttribute)). This is based off the old COM XmlDocument object and is available as far back as version 1.1 of the framework.

نصائح أخرى

System.Xml

Something like

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;
}

Sort of thing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top