XPath beginner's note (1)

Source: Internet
Author: User
Tags xslt xpath contains

[This article is a reference to www.w3school.com.cn]

 

XPath is a language used to search for information in XML documents. XPath can be used to traverse elements and attributes in XML documents.

XPath is the main element of W3C XSLT standards, and XQuery and xpointer are also built on XPath expressions.

What is XPath?

  • XPath uses path expressions for navigation in XML documents
  • XPath contains a standard function library
  • XPath is the main element in XSLT.
  • XPath is a W3C Standard

XPath path expression

XPath uses path expressions to select nodes or node sets in XML documents. These path expressions are very similar to the expressions we see in conventional computer file systems.

XPath Standard Functions

XPath contains more than 100 built-in functions. These functions are used for string value, numeric value, date and time comparison, node and QNAME processing, sequence processing, logical value, and so on.

 

XPath terminology

Node)

There are seven types of nodes in XPath: elements, attributes, text, namespaces, processing commands, comments, and document (Root) nodes. XML documents are treated as node trees. The root of a tree is called a document node or a root node.

See the following XML document:

 

<? XML version = "1.0" encoding = "ISO-8859-1"?>
<Bookstore>

<Book>

<Title lang = "en"> Harry Potter </title>

<Author> j k. Rowling </author>

<Year> 2005 </year>

<Price> 29.99 </price>

</Book>

</Bookstore>

Node example in the XML document above:

<Bookstore> (document node)

<Author> j k. Rowling </author> (element node)

Lang = "en" (attribute node)

Basic value (or atomic value)

The basic value is a node with no parent or child.

Example of the basic value:

J k. Rowling

"EN"

Item)

A project is a basic value or node.

Node relationship

Parent)

Each element and attribute has a parent.

In the preceding example, the book element is the parent of the title, author, year, and price elements.

Child)

Element nodes can have zero, one, or more sub-nodes.

In the above example, the title, author, year, and price elements are all child of the book element.

Sibling)

Nodes with the same parent

In the preceding example, the title, author, year, and price elements are all siblings.

Advanced (ancestor)

The parent and parent of a node.

In the above example, the title element is a book element and a bookstore element.

Descendant (descendant)

The child of a node, the child of the child, and so on.

In the above example, the future generations of bookstore are book, title, author, year, and price.

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.