Hướng dẫn XML

TRANG CHỦ XML Giới thiệu XML Cách sử dụng XML Cây XML Cú pháp XML Phần tử XML Thuộc tính XML Không gian tên XML Hiển thị XML HttpRequest XML Trình phân tích cú pháp XML DOM XML XPath XML XSLT XML XQuery XML XML XLink Trình xác thực XML DTD XML Lược đồ XML Máy chủ XML Ví dụ về XML Câu đố XML Chứng chỉ XML

XML AJAX

Giới thiệu AJAX AJAX XMLHttp Yêu cầu AJAX Phản hồi AJAX Tệp XML AJAX AJAX PHP AJAX ASP Cơ sở dữ liệu AJAX Ứng dụng AJAX Ví dụ về AJAX

DOM XML

Giới thiệu DOM Nút DOM Truy cập DOM Thông tin nút DOM Danh sách nút DOM DOM Traversing Điều hướng DOM DOM Nhận giá trị Nút thay đổi DOM DOM Xóa các nút Nút thay thế DOM DOM Tạo nút DOM Thêm nút Nút nhân bản DOM Ví dụ về DOM

Hướng dẫn XPath

Giới thiệu XPath Nút XPath Cú pháp XPath Trục XPath Toán tử XPath Ví dụ về XPath

Hướng dẫn XSLT

Giới thiệu XSLT Ngôn ngữ XSL Chuyển đổi XSLT XSLT <template> XSLT <value-of> XSLT <for-each> XSLT <sắp xếp> XSLT <if> XSLT <chọn> Áp dụng XSLT XSLT trên máy khách XSLT trên Máy chủ XSLT Chỉnh sửa XML Ví dụ về XSLT

Hướng dẫn XQuery

Giới thiệu XQuery Ví dụ về XQuery XQuery FLWOR HTML XQuery Điều khoản XQuery Cú pháp XQuery XQuery Thêm Chọn XQuery Hàm XQuery

DTD XML

Giới thiệu DTD Khối xây dựng DTD Phần tử DTD Các thuộc tính DTD Phần tử DTD so với Attr Thực thể DTD Ví dụ về DTD

Lược đồ XSD

Giới thiệu XSD XSD Cách thực hiện XSD <schema> Phần tử XSD Thuộc tính XSD Hạn chế XSD

XSD Complex

Phần tử XSD XSD trống Chỉ các phần tử XSD Chỉ văn bản XSD XSD hỗn hợp Chỉ báo XSD XSD <nhiều> XSD <anyAttribute> Thay thế XSD Ví dụ về XSD

Dữ liệu XSD

Chuỗi XSD Ngày XSD XSD Numeric XSD Misc Tham chiếu XSD

Dịch vụ web

Dịch vụ XML WSDL XML SOAP XML RDF XML RSS XML

Người giới thiệu

Các loại nút DOM Nút DOM DOM NodeList DOM NamedNodeMap Tài liệu DOM Phần tử DOM Thuộc tính DOM Văn bản DOM DOM CDATA Bình luận DOM DOM XMLHttpRequest Trình phân tích cú pháp DOM Phần tử XSLT Hàm XSLT / XPath

Trục XPath


Tài liệu Ví dụ về XML

Chúng tôi sẽ sử dụng tài liệu XML sau trong các ví dụ dưới đây.

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>
  <title lang="en">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="en">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore>

Trục XPath

Một trục thể hiện mối quan hệ với nút ngữ cảnh (hiện tại) và được sử dụng để định vị các nút liên quan đến nút đó trên cây.

AxisName Result
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attribute Selects all attributes of the current node
child Selects all children of the current node
descendant Selects all descendants (children, grandchildren, etc.) of the current node
descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself
following Selects everything in the document after the closing tag of the current node
following-sibling Selects all siblings after the current node
namespace Selects all namespace nodes of the current node
parent Selects the parent of the current node
preceding Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes
preceding-sibling Selects all siblings before the current node
self Selects the current node


Biểu thức Đường dẫn Vị trí

Đường dẫn vị trí có thể là tuyệt đối hoặc tương đối.

Đường dẫn vị trí tuyệt đối bắt đầu bằng dấu gạch chéo (/) và đường dẫn vị trí tương đối thì không. Trong cả hai trường hợp, đường dẫn vị trí bao gồm một hoặc nhiều bước, mỗi bước được phân tách bằng dấu gạch chéo:

An absolute location path:

/step/step/...

A relative location path:

step/step/...

Mỗi bước được đánh giá dựa trên các nút trong tập hợp nút hiện tại.

Một bước bao gồm:

  • một trục (xác định mối quan hệ cây giữa các nút đã chọn và nút hiện tại)
  • kiểm tra nút (xác định một nút trong một trục)
  • không hoặc nhiều vị từ (để tinh chỉnh thêm tập hợp nút đã chọn)

Cú pháp cho bước vị trí là:

axisname::nodetest[predicate]

Các ví dụ

Example Result
child::book Selects all book nodes that are children of the current node
attribute::lang Selects the lang attribute of the current node
child::* Selects all element children of the current node
attribute::* Selects all attributes of the current node
child::text() Selects all text node children of the current node
child::node() Selects all children of the current node
descendant::book Selects all book descendants of the current node
ancestor::book Selects all book ancestors of the current node
ancestor-or-self::book Selects all book ancestors of the current node - and the current as well if it is a book node
child::*/child::price Selects all price grandchildren of the current node