我们先来认识一下XPath,
我们使用books.xml作为演示的文件:
#region books.xml
//<?xml version='1.0' encoding="gb2312"?>
//<!-- This file represents a fragment of a book store inventory database -->
//<bookstore>
// <book genre="文学作品">
// <title>钢铁怎样炼成的</title>
// <author>
// <first-name>尼古拉</first-name>
// <last-name>奥斯特洛甫斯基</last-name>
// </author>
// <price type="RMB">8.99</price>
// </book>
// <book genre="小说">
// <title>大骗子</title>
// <author>
// <first-name>希尔曼</first-name>
// <last-name>梅尔维尔</last-name>
// </author>
// <price type="RMB">11.99</price>
// </book>
// <book genre="物理">
// <title>相对论</title>
// <author>
// <name>爱因斯坦</name>
// </author>
// <price type="RMB">9.99</price>
// </book>
//</bookstore>
#endregion
什么是XPath?
XPath使用路径表达式在XML文档中进行导航 XPath包含一个标准函数库 XPath是XSLT中的主要元素 XPath是一个W3C标准
--------------------------------------------------------------------------------
XPath路径表达式
XPath使用路径表达式来选取XML文档中的节点或者节点集。这些路径表达式和我们在常规的电脑文件系统中看到的表达式非常相似。
--------------------------------------------------------------------------------
XPath标准函数
XPath含有超过100个内建的函数。这些函数用于字符串值、数值、日期和时间表、节点和QName处理、序列处理、逻辑值等等。
--------------------------------------------------------------------------------
XPath在XSLT中使用
XPath是XSLT标准中的主要元素。如果没有XPath方面的知识,您就无法创建XSLT文档。 XQuery和XPointer均构建于XPath表达式之上。XQuery 1.0和XPath 2.0共享相同的数据模型,并支持相同的函数和运算符。
--------------------------------------------------------------------------------
XPath是W3C标准
XPath于1999年11月16日成为W3C标准。 XPath被设计供XSLT、XPointer以及其他XML解析器软件使用。