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);//中间的参数怎么写

解决方案 »

  1.   

    That is a XPath string. Follow is explanation about XPath from .NET document. XML Path Language (XPath) is a language used to create expressions that can address parts of an XML document, manipulate strings, numbers, and Booleans, and can match a set of nodes in the document. XPath is used by both XSL Transformations (XSLT) and XPointer, and models an XML document as a tree of nodes of different types, including element, attribute, and text. XPath expressions can identify these nodes in the XML document based on their type, name, and values, as well as the relationship of a node to other nodes in the document.Hope it could be help.
      

  2.   

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

  3.   

    if you read the documentation carefully,XmlNode.SelectSingleNode Method (String)
    ....
    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
      

  4.   

    surely you can compile the code, as long as you give a string at that position. but you can't get the result you want if you give "abc", because parser don't understand it.
    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.