XPath syntax rules

zhaozj2021-02-16  52

XPath syntax rules

XPath uses the path expression to determine the node in the XML document.

We will use the following XML document description XPath syntax

C2688-67037 LCD LCD display 1 358.00 C2688-67061 Speaker 1 16.50 C2688-67010 Mouse 1 8.50

Node positioning:

The XML text can be represented as a node that identifies the XML document using the XPath using the pattern expression of the tree structure node.

The mode of an XPath is to use a backslash "/" separate sub-element name description path

The following XPath expression selects all Price Elements in Elements in Order Elements / Order / Item / Price

Note: Use the "/" path to start the absolute path of the element.

No "/" path starts representing the relative path of the element

Item / price

Start with the "//" path to represent all the elements that meet the conditions of the entire document

The following XPath Expression Selects the Item Elements in the Document // Item

Select unknown elements

Tongcar "*" can be used to select unknown XML elements

The following XPath Expression Selects the child elements belonging to all Item elements in the element Order

/ Order / item / *

The following XPath expression selects the element of all grandson under order / * / price under ORDER

The following XPath Expressions Select all Price Elements with Two Ancestors / * / * / Price

The following XPath Expressions Select Document All Elements // *

Branch

Use square brackets [] can specify specific elements

The following XPath Expression Select the child element of the first item in Order

/ Order / item [1]

The following XPath expression selects the last item of the last item in Order / Order / Item [last ()]]

The following XPath Expression Select Element Order Item Element / Order / Item [price]

The following XPath expression, Item element /Iden/item[Price =16.50 from element Order

The following XPath expression is selected from the ITEM element belonging to the element Order, the Price Element with Price is equal to 12.60 /Ider/Item [Price =16.50]/price

Select a few paths

In the XPath expression, you can choose several paths using the "|" operator. Essentially logic "and" operation

The following XPath expression is selected from the ItemNumber and Description Elements / Order / Item / ItemNumber | / ORDER / ITEM / ITEMNumBer | / Order / Item / Description, select all ItemNumber and Description Elements from the documentation. Itemnumber | // Description

The following XPath expression, select all ItemNumber, Description and Price Elements from the document // itemnumber | // description | // Price

The following XPath expression is selected as all ItemNumber elements under the ORDER and select all description elements from the document / Order / item / itemnumber | // Description

Select Properties in XPath, all properties use @ prefix

The following XPath expression selects all the properties named Catalog @ Catalog

The following XPath expression selects all Item elements with a Catalog property // item [@catalog]

The following XPath expression selects all Item elements with any properties // item [@ *]

The following XPath expression selects all ITEM elements with Catalog equal to "parts" attributes // item [@ catalog = "parts"]

转载请注明原文地址:https://www.9cbs.com/read-19911.html

New Post(0)