惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - Scott Xu(南方小鬼)

C#发现之旅第一讲 C#-XML开发 XPath Operators Basic XPath Syntax Basic XPath Basic XSLT Basic 深入浅出之正则表达式(二) 深入浅出之正则表达式(一) 通过Microsoft.Feeds获取feeds My Best Loves C#(3.0) 深入浅出系列之相关概念 C#(3.0) 深入浅出系列 Expression Studio 2.0 中文版发布了 一定能影响你的简单十句话 众说不一,“八零”后程序员到底怎么了? SQL Server 2005 实用例子 你最应该雇佣的程序员的十个特征 - Scott Xu(南方小鬼) 多个检索页面,分析,Silverlight绘图 .net component 开发系列1(学习) C# 中的设计模式3:Abstract Factory(学习笔记)
XPath Axes Basic
Scott Xu(南方小鬼) · 2008-08-31 · via 博客园 - Scott Xu(南方小鬼)

The XML Example Document

We will use the following XML document in the examples below.

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
  <book>
    <title lang="eng">Harry Potter</title>
    <price>29.99</price>
  </book>
  <book>
    <title lang="eng">Learning XML</title>
    <price>39.95</price>
  </book>
</bookstore>

XPath Axes

An axis defines a node-set relative to the current node.

一条主线指定了一系列的节点和当前节点的关系

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 everything in the document that is before the start tag of the current node

选择文档中当前节点前的所有节点

preceding-sibling

Selects all siblings before the current node

选择当前节点前的所有同科节点

self

Selects the current node

选择当前节点

Location Path Expression位置表达式

A location path can be absolute or relative.

可以是绝对的也可以是相对的

An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash:

一个绝对的路径以"/"开始,两种表示式都有一级或多级构成,级用"/"分开

An absolute location path:

/step/step/...

A relative location path:

step/step/...

Each step is evaluated against the nodes in the current node-set.

每一级都是根据当前节点的在节点集的位置来执行的

A step consists of:级构成:

  • an axis (defines the tree-relationship between the selected nodes and the current node) 主线(规定一个当前节点和所先节点的关系树)
  • a node-test (identifies a node within an axis) 一个节点测试(在主线中辨认一个节点)
  • zero or more predicates (to further refine the selected node-set) 一个或多个谓词(进一步挑选选定的节点集)

The syntax for a location step is:语法

axisname::nodetest[predicate]

Examples:

Example

Result

child::book

Selects all book nodes that are children of the current node

选择当前节点的所有的book节点

attribute::lang

Selects the lang attribute of the current node

选择当前节点的lang 属性

child::*

Selects all children of the current node

选择当前节点的所有子节点

attribute::*

Selects all attributes of the current node

选择当前节点的所有属性

child::text()

Selects all text child nodes of the current node

选择当前节点的所有文本子节点

child::node()

Selects all child nodes of the current node

选择当前节点的所有子节点

descendant::book

Selects all book descendants of the current node

选择当节点的所有book胄

ancestor::book

Selects all book ancestors of the current node

选择当前节点的所有book节点的祖,根

ancestor-or-self::book

Selects all book ancestors of the current node - and the current as well if it is a book node

选择当前节点的book元素的根节点或它自己(如果它也是一个book节点的话)

child::*/child::price

Selects all price grandchildren of the current node