Method memo for reading XML documents with namespaces

Source: Internet
Author: User

For a long time did not do XML aspects of parsing, today received a small task, need to parse the XML inside the field content, incidentally reviewed the XPath knowledge. The XML that needs parsing is the kind of document to be namespace, and at the beginning of the parsing, I feel that it is the name space that has dealt with the problem before, but the time is long, forgotten, and not recorded.

Toss it for a while and finally find a way. NET to read XML documents with XML namespaces is really cumbersome and not straightforward enough. Anyway, keep a record of the solution to save you from being tossed around again.

StringReader TextReader = new StringReader (surveyproject.surverycontent);            XPathDocument xd = new XPathDocument (TextReader);            XPathNavigator navigator = xd. CreateNavigator ();               --Join the namespace            NameTable nt = new NameTable ();            XmlNamespaceManager nsmgr = new XmlNamespaceManager (NT);            Nsmgr. AddNamespace ("RC", "http://sechemas.hirede.com/2011/05/Apps/ReferenceChecking");                      --When used, it has to be passed            xpathnavigator pathnavigator = navigator. selectSingleNode ("//rc:basicinformation/rc:name", nsmgr);            if (pathnavigator! = null)            {                return pathnavigator.value;            }

  

Method memo for reading XML documents with namespaces

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.