XPath ½Úµã
ÔÚ XPath ÖУ¬ÓÐÆßÖÖÀàÐÍµÄ½Úµã£ºÔªËØ¡¢ÊôÐÔ¡¢Îı¾¡¢ÃüÃû¿Õ¼ä¡¢´¦ÀíÖ¸Áî¡¢×¢ÊÍÒÔ¼°Îĵµ½Úµã£¨»ò³ÆÎª¸ù½Úµã£©¡£
XPath ÊõÓï
½Úµã£¨Node£©
ÔÚ XPath ÖУ¬ÓÐÆßÖÖÀàÐÍµÄ½Úµã£ºÔªËØ¡¢ÊôÐÔ¡¢Îı¾¡¢ÃüÃû¿Õ¼ä¡¢´¦ÀíÖ¸Áî¡¢×¢ÊÍÒÔ¼°Îĵµ£¨¸ù£©½Úµã¡£XML ÎĵµÊDZ»×÷Ϊ½ÚµãÊ÷À´¶Ô´ýµÄ¡£Ê÷µÄ¸ù±»³ÆÎªÎĵµ½Úµã»òÕ߸ù½Úµã¡£
Çë¿´ÏÂÃæÕâ¸ö XML Îĵµ£º
<?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>
ÉÏÃæµÄXMLÎĵµÖеĽڵãÀý×Ó£º
<bookstore> £¨Îĵµ½Úµã£© <author>J K. Rowling</author> £¨ÔªËؽڵ㣩 lang="en" £¨ÊôÐԽڵ㣩
»ù±¾Öµ£¨»ò³ÆÔ×ÓÖµ£¬Atomic value£©
»ù±¾ÖµÊÇÎÞ¸¸»òÎÞ×ӵĽڵ㡣
»ù±¾ÖµµÄÀý×Ó£º
J K. Rowling "en"
ÏîÄ¿£¨Item£©
ÏîÄ¿ÊÇ»ù±¾Öµ»òÕ߽ڵ㡣
½Úµã¹ØÏµ
¸¸£¨Parent£©
ÿ¸öÔªËØÒÔ¼°ÊôÐÔ¶¼ÓÐÒ»¸ö¸¸¡£
ÔÚÏÂÃæµÄÀý×ÓÖУ¬book ÔªËØÊÇ title¡¢author¡¢year ÒÔ¼° price ÔªËØµÄ¸¸£º
<book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
×Ó£¨Children£©
ÔªËØ½Úµã¿ÉÓÐÁã¸ö¡¢Ò»¸ö»ò¶à¸ö×Ó¡£
ÔÚÏÂÃæµÄÀý×ÓÖУ¬title¡¢author¡¢year ÒÔ¼° price ÔªËØ¶¼ÊÇ book ÔªËØµÄ×Ó£º
<book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
ͬ°û£¨Sibling£©
ÓµÓÐÏàͬµÄ¸¸µÄ½Úµã
ÔÚÏÂÃæµÄÀý×ÓÖУ¬title¡¢author¡¢year ÒÔ¼° price ÔªËØ¶¼ÊÇͬ°û£º
<book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
Ïȱ²£¨Ancestor£©
ij½ÚµãµÄ¸¸¡¢¸¸µÄ¸¸£¬µÈµÈ¡£
ÔÚÏÂÃæµÄÀý×ÓÖУ¬title ÔªËØµÄÏȱ²ÊÇ book ÔªËØºÍ bookstore ÔªËØ£º
<bookstore> <book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>
ºó´ú£¨Descendant£©
ij¸ö½ÚµãµÄ×Ó£¬×ÓµÄ×Ó£¬µÈµÈ¡£
ÔÚÏÂÃæµÄÀý×ÓÖУ¬bookstore µÄºó´úÊÇ book¡¢title¡¢author¡¢year ÒÔ¼° price ÔªËØ£º
<bookstore> <book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore>