If the XPath expression does not include a prefix, it is assumed that the namespace Uniform Resource Identifier (URI) is the empty namespace. To set mapping for a content control, use the SetMapping method or the SetMappingByNode method.
expression An expression that returns an 'XMLMapping' object. Notice in the previous example that when a node is modified in the selected XmlNodeList the underlying document is also modified. Returns a String that represents the XPath for the XML mapping, which evaluates to the currently mapped XML node. Therefore, if you iterate through the node list and modify the value of a node, that node is also updated in the document it came from. This (.) Īll XmlNodeList objects are synchronized with the underlying document.
If you do not want to start at the document element, but want to start from the first child of the document element, you can code the select statement as follows: (. Setting the starting point for the XPath query sets the context node, which is the starting point for the XPath query. The examples above start the XPath query at the document element. Select all nodes where the book price is greater than 10.00.ī = price.ToString() ' Select all nodes where the book price is greater than 10.00.ĭim nodeList As XmlNodeList = root.SelectNodes( _ī = price.ToString() ' Load the document and set the root element. The bookstore.xml file (which is provided at the end of this topic) is used as the input file.
Finally, the updated file is written to the console. The price for each book in the selected list is then programmatically reduced by ten percent. The next example uses the SelectNodes method to select all the book nodes in which the price is greater than a specified amount. Select and display the first node in which the author's Nsmgr.AddNamespace("bk", "urn:newbooks-schema") XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable) Load the document and set the root element. ' Select and display the first node in which the author'sĭim node As XmlNode = root.SelectSingleNode( _ Dim doc As New XmlDocument()ĭim root As XmlNode = doc.DocumentElementĭim nsmgr As New XmlNamespaceManager(doc.NameTable) The following example uses the SelectSingleNode method to select the first book node in which the author's last name meets the specified criteria. The SelectNodes method returns an XmlNodeList that contains the matching nodes. The SelectSingleNode method returns the first node that matches the selection criteria. The DOM classes provide two methods for XPath selection: the SelectSingleNode method and the SelectNodes method. You can use XPath to find a single, specific node or to find all nodes that match some criteria. The XML Document Object Model (DOM) contains methods that allow you to use XML Path Language (XPath) navigation to query information in the DOM.