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

推荐订阅源

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 Axes 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 Operators Basic
Scott Xu(南方小鬼) · 2008-08-31 · via 博客园 - Scott Xu(南方小鬼)

An XPath expression returns either a node-set, a string, a Boolean, or a number.

一个 XPath 表达式可以返回一个节点集,一个字符串,一个布尔值,或一个数值

XPath Operators

Below is a list of the operators that can be used in XPath expressions:

下面是一些可以用在XPath表达式中的操作符的清单:

Operator Description Example Return value
|

Computes two node-sets

返回两个节点集

//book | //cd

Returns a node-set with all book and cd elements

返回一个所有book 元素和cd元素的节点集

+ Addition加 6 + 4 10
- Subtraction减 6 - 4 2
* Multiplication乘

6 * 4

24
div Division除 8 div 4 2
= Equal等于 price=9.80 true if price is 9.80
false if price is 9.90
!= Not equal不等于 price!=9.80 true if price is 9.90
false if price is 9.80
< Less than小于 price<9.80 true if price is 9.00
false if price is 9.80
<= Less than or equal to小于等于 price<=9.80 true if price is 9.00
false if price is 9.90
> Greater than大于 price>9.80 true if price is 9.90
false if price is 9.80
>=

Greater than or equal to大于等于

price>=9.80 true if price is 9.90
false if price is 9.70
or or或 price=9.80 or price=9.70 true if price is 9.80
false if price is 9.50
and and 且 price>9.00 and price<9.90 true if price is 9.80
false if price is 8.50
mod Modulus (division remainder)取余 5 mod 2

Examples

Let's try to learn some basic XPath syntax by looking at some examples.

通过实例学习基本的xpath语法

The XML Example Document

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

使用下面的xml文档来做为范例

"books.xml":

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>
    <year>2003</year>
    <price>49.99</price>
  </book>
  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

View the "books.xml" file in your browser

Selecting Nodes 选择节点

We will use the Microsoft XMLDOM object to load the XML document and the selectNodes() function to select nodes from the XML document:

我们通过使用Microsoft  的XMLDOM对象来加载XML文档和selectNodes() 函数来从XML文档中选择节点

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("books.xml")

xmlDoc.selectNodes(path expression)

Select all book Nodes选择所有的book节点

The following example selects all the book nodes under the bookstore element:

下例选择bookstore元素的所有的book 节点

xmlDoc.selectNodes("/bookstore/book")

Select the First book Node选择第一个book节点

The following example selects only the first book node under the bookstore element:

xmlDoc.selectNodes("/bookstore/book[0]")

Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!

:W3C标准为使用[1]来选择第一个

A Workaround! 解决办法!

To solve the [0] and [1] problem in IE5+, you can set the SelectionLanguage to XPath.

为了解决这个问题,你可以通过为XPath设置SelectionLanguage

The following example selects only the first book node under the bookstore element:

xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.selectNodes("/bookstore/book[1]")

Select the prices选择price元素

The following example selects the text from all the price nodes:

xmlDoc.selectNodes("/bookstore/book/price/text()") 

Selecting price Nodes with Price>35选择price值大于35的元素

The following example selects all the price nodes with a price higher than 35:

xmlDoc.selectNodes("/bookstore/book[price>35]/price")