XmlDocument doc = new XmlDocument();doc.load(xmlpath);//xml文件见上XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);nsmgr.AddNamespace(String.Empty, "http://www.test.com/xml/ParkingList");XmlNode node = doc.SelectSingleNode(???, nsmgr);//中间的参数怎么写
I can compile code as follownsmgr.AddNamespace("abc", "http://www.test.com/xml/ParkingList");XmlNode node = doc.SelectSingleNode("//abc:buildingGroup[@name = ...], nsmgr);"abc" is added by me,but I don't understand it and I want to know how implement use String.Empty
....
If the XPath expression does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace, you must still use the XmlNamespaceManager and add a prefix and namespace URI to it; otherwise, you will not get a selected node.....you will know it is not possible to get nodes with the default namespace using XPath and SelectNodes
Simply to say XPath is similar to directory path. Like you can use "c:\temp\abc.doc" to locate the abc.doc file in file system, you could use "../Node1/Node2" to locate the node in xml file. Give you some samples below.Find all title elements one or more levels deep in the bookstore (arbitrary descendants).
bookstore//titleNote that this is different from the following pattern, which finds all title elements that are grandchildren of bookstore elements.
bookstore/*/titleFind emph elements anywhere inside book excerpts, anywhere inside the bookstore.
bookstore//book/excerpt//emphFind all titles one or more levels deep in the current context. Note that this situation is essentially the only one in which the period notation is required.
.//titleFind all element children of author elements.
author/*You could find more samples in MSDN or online.
Hope it could be help.