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