Methods for reading Xml documents with namespaces:

Source: Internet
Author: User

Methods for reading Xml documents with namespaces:

I haven't done xml parsing for a long time. Today I have received a small task. I need to parse the fields in the xml, and I have reviewed the xpath knowledge. The xml to be parsed is the kind of document to be resolved to namespace. When I first encountered a problem during the parsing, I felt that the namespace was playing a strange role. I was impressed that I had handled this problem before, but it was a long time ago, they are all forgotten and not recorded.

After a while, I finally found a method. It is really troublesome to read xml documents with xml Namespaces in. NET. In any case, record the solution and try again later.

StringReader textReader = new StringReader (surveyProject. surveryContent); XPathDocument xd = new XPathDocument (textReader); XPathNavigator navigator = xd. createNavigator (); -- add namespace NameTable nt = new NameTable (); XmlNamespaceManager nsmgr = new XmlNamespaceManager (nt); nsmgr. addNamespace ("rc", "http://sechemas.hirede.com/2011/05/Apps/ReferenceChecking"); -- XPathNavigator pathNavigator = Navigator. SelectSingleNode ("// rc: BasicInformation/rc: Name", nsmgr); if (pathNavigator! = Null) {return pathNavigator. Value ;}

  

Related Article

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.