0

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

2 Answers 2

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.