In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to understand XPath expression syntax". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
XPath path expression
XPath is the XML path language, which is a language used to determine the location of a part of an XML (a subset of the standard general markup language) document. XPath is based on the tree structure of XML and provides the ability to find nodes in the data structure tree. XPath uses path expressions to determine nodes in an XML document.
Sample XML document
We will use the following XML document to describe the XPath syntax
C2688-67037 LCD LCD 1 358.00 C2688-67061 Speaker 116.50 C2688-67010 Mouse 18.50 Select "/" from the root node
XML documents can be expressed as tree-structured nodes XPath uses pattern expressions to identify nodes of XML documents. The pattern of an XPath is to use a backslash "/" to separate the child element name from the XPath expression under the path to select all the price elements in the element item under the element order
/ order/item/price
Note: start with the "/" path to represent the absolute path of the element, instead of the "/" path to represent the relative path of the element
Item/price
Select "/" from the entire document
Start with the "/ /" path to represent all elements of the entire document that meet the criteria, regardless of the XPath expression below their location to select all item elements in the document
/ / item
Select unknown element "*"
The wildcard "*" can be used to select the XPath expression below the unknown XML element to select the child elements to which all item elements in the order element belong
/ order/item/*
The following XPath expression selects the price element for all grandchildren under the element order
/ order/*/price
The following XPath expression selects all price elements with two ancestors
/ price
The following XPath expression selects all elements of the document
/ / *
Select branch "[]" (predicate)
Use square brackets [] to specify the XPath expression below a specific element to select the child elements of the first item in the element order
/ order/item [1]
The following XPath expression selects the child elements of the last item in the element order
/ order/item [last ()]
The following XPath expression selects the item element with the price element in the element order
/ order/item [price]
The following XPath expression selects the item element with the element price equal to 12.60from the element order
/ order/item [price=16.50]
The following XPath expression selects the price element with the element price equal to 12.60from the item element belonging to element order
/ order/ item [price = 16.50] / price
Select several paths "|"
In XPath expressions, you can select several paths using the "|" operator. Essentially the XPath expression under the logical "and" operation, selecting all itemNumber and description elements from the item elements that belong to order
/ order/item/itemNumber | / order/item/description
The following XPath expression selects all itemNumber and description elements from the document
/ / itemNumber | / / description
The following XPath expression selects all itemNumber, description, and price elements from the document
/ / itemNumber | / / description | / / price
The following XPath expression, select all itemNumber elements that belong to item in order and select all description elements from the document
/ order/item/itemnumber | / / description
Select property "@"
In XPath, all attributes use the XPath expression under the @ prefix, and all attributes named catalog are selected
/ / @ catalog
The following XPath expression selects all item elements with the catalog attribute
/ / item [@ catalog]
The following XPath expression selects all item elements with any attribute
/ / item [@ *]
The following XPath expression selects all item elements with a catalog equal to "parts" attribute
/ / item [@ catalog= "parts"]
Summary
(1) the most useful path expressions are listed below the selected node:
The expression describes that nodename selects all the children of this node. / Select from the root node. / / Select nodes in the document from the current node selected by the match, regardless of their location. . Select the current node. .. Select the parent node of the current node. @ Select the property.
(2) the Predicates predicate is used to find a specific node or a node that contains a specified value. The predicate is embedded in square brackets []. (3) selecting unknown node XPath wildcards can be used to select unknown XML elements.
The wildcard description * matches any element node. @ * matches any attribute node. Node () matches any type of node.
(4) Select several paths by using the "|" operator in the path expression, you can select several paths. For more information about XPath syntax rules, please visit W3CSchool.
That's all for "how to understand XPath expression syntax". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.