Concise xpath syntax

Source: Internet
Author: User
Tags xml example

 

Concise xpath syntax
Xpath is a standard. If your e file is good enough, you can open the help of Ms SQL server, and then click Microsoft Data Access Component (MDAC) 2.6 and Extensible Markup Language (XML) 2.6 documents
There is a chapter called XML> rule treference> XPath Syntax
Here is a detailed description. If you are bored, let's take a look at the following simple description. If you only want to know how to use Xpath to find the Node you want, the following knowledge is enough:
 
XPath is an XML query statement, which is similar to the SQL role. The XML below is used as an example to describe how to parse XPath.


Empire Burlesque
Bob Dylan
10.90


Hide your heart
Bonnie Taylor
9.90


Greatest Hits
Dolly Parton
9.90

Locate metric point
XML is the structure of structured data, similar to the structure of the Internal data library of the Case System, and XPath is also similar to the path naming method of the Case System. However, XPath is a Pattern. You can select all nodes that match a Pattern in the XML example. For example, to select all the price elements in cd under catalog, you can use:
/Catalog/cd/price

If the start of XPath is a diagonal line (/), it indicates the opposite path. If the start is two diagonal lines (//), it indicates that all elements in the file that match the pattern will be selected, even different segments in the topology will be selected. The following method selects all the elements named cd in the file (any member in the file will be selected ):
// Cd

Select unknown elements
You can use Wildcards (*) to select unknown elements. The following method selects all child elements of/catalog/cd:
/Catalog/cd /*

The following method selects all the child elements of the catalog, including the elements with price as the child element.
/Catalog/*/price

The following statement Selects all the elements named price with two parent nodes.
/*/Price

The following selection method selects all elements in the file.
//*

It should be noted that the XPath method must start with two oblique headers (//) to access non-linear elements (//), if you want to access an unknown element, you can use the asterisk (*). A star token can only represent an element with an unknown name. It cannot represent an element with an unknown sequence.
Select Branch
You can select a branch if you use the middle-range rule. The following method extracts the first element named cd from the child element of catalog. The definition of XPath does not contain 0th elements.
/Catalog/cd [1]

The following method selects the last cd element in the catalog: (XPathj does not define the first () function, the first element can be extracted using [1] of the preceding example.
/Catalog/cd [last ()]

The following method selects all/catalog/cd elements containing the price sub-element.
/Catalog/cd [price]

The following sort method selects all/catalog/cd elements whose price value is equal to 10.90.
/Catalog/cd [price = 10.90]

The following statement selects the price element value, which is equal to the price element of all/catalog/cd elements of 10.90.
/Catalog/cd [price = 10.90]/price

Select more than one path
Use Or to calculate the RMB (|) to select more than one path. For example:
/Catalog/cd/title | catalog/cd/artist

Select all titles and artist elements.
// Title | // artist

Select all titles, artist, and price
// Title | // artist | // price

Optional
In XPath, you can also choose between elements. All features start. For example, in the selection file, all the features called country are as follows:
// @ Country

Select all cd elements containing the country nature:
// Cd [@ country]

The following selection method selects all cd elements with attention
// Cd [@ *]

The following statement selects the cd element whose country encoding is UK.
// Cd [@ country = 'U']

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.