XPath – Study Notes

/catalog/cd/price   -- get price elements under catelog/cd

//cd  -- get all cd elements of file

/catalog/cd/* -- get all elements under cd

/catalog/*/price

/*/*/price

//*  -- get all elements of file

--Get elements

/catalog/cd[0] -- get the first element which name is cd under catalog

/catalog/cd[last()] -- get the last element

/catelog/cd[price] -- get all cd elements which contain price child element

/catalog/cd[price=10.90] -- get all cd elements which contain price child element and value is 10.90

/catalog/cd[price-10.90]/price -- get all price elements which cd contain price child element and value is 10.90

--Get more than one path

/catalog/cd/title | catalog/cd/artist

//title | //artist

//title | //artist | //price

--Choose attribute

//@country  --choose all country attribute

//cd[@country] -- choose all cd elements contain country attribute

//cd[@*] -- choose all cd elements contain attribute

//cd[@country="UK"] -- choose all cd elements contain attribute and value is UK

//cd[@country="UK"][@name="test"] -- choose all cd elements contain country & name attributes and values are UK & test

路慢慢其休远羲,吾将上下而求所
原文地址:https://www.cnblogs.com/garinzhang/p/2550024.html