2
這是我正在使用的XML片段(還有更多),我試圖運行XPath表達式來查找Item
部分中的ASIN
節點,同時確認Author
不是JK Rowling
。在XPath中選擇父節點?
我嘗試這樣做:/ItemSearchResponse/Items/Item/ItemAttributes[Author = "J.K. Rowling"]/parent::
但它沒有返回比賽,你能有人指導我訪問父屬性?
<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse>
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Condition>New</Condition>
<DeliveryMethod>Ship</DeliveryMethod>
<Keywords>Rowling Fiction English</Keywords>
<MerchantId>Amazon</MerchantId>
<ResponseGroup>Small</ResponseGroup>
<SearchIndex>Books</SearchIndex>
</ItemSearchRequest>
</Request>
<TotalResults>171</TotalResults>
<TotalPages>18</TotalPages>
<Item>
<ASIN>0747557462</ASIN>
<ItemAttributes>
<Author>Sarah Brown</Author>
<Author>Gil McNeil</Author>
<Creator Role="Foreword">J.K. Rowling</Creator>
<Manufacturer>Bloomsbury UK</Manufacturer>
<ProductGroup>Book</ProductGroup>
<Title>Magic</Title>
</ItemAttributes>
</Item>
</Items>
</ItemSearchResponse>
它應該拋出一個語法錯誤:'parent ::'後面必須跟着某種NodeTest,例如'parent :: *'或'parent :: Item'。 –