Xml 在XPath中选择父节点?

Xml 在XPath中选择父节点?,xml,xpath,Xml,Xpath,下面是我正在使用的一段XML(还有更多),我正在尝试运行XPath表达式,以在项部分中找到ASIN节点,同时确认作者不是JK Rowling 我试过这样做:/itemsearchsresponse/Items/Item/itemtattributes[Author=“J.K.Rowling”]/parent:: 但是它没有返回匹配项,您能指导我访问父属性吗 <?xml version="1.0" encoding="UTF-8"?> <ItemSearchRespons

下面是我正在使用的一段XML(还有更多),我正在尝试运行XPath表达式,以在
部分中找到
ASIN
节点,同时确认
作者
不是
JK Rowling

我试过这样做:
/itemsearchsresponse/Items/Item/itemtattributes[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>

真的
新的
船
罗琳小说英语
亚马逊
小的
书
171
18
0747557462
布朗
吉尔·麦克尼尔
J.K.罗琳
布卢姆斯伯里英国
书
魔术

可以通过XPath中的
选择父级。
,但通常使用祖先中较高的谓词更为简洁:

//Item[not(ItemAttributes/Author="J.K. Rowling")]/ASIN

将选择
Item
中的所有
ASIN
元素,这些元素没有
itemtattributes/Author
,字符串值为
“J.K.Rowling”

它将抛出语法错误:
父项:
必须后跟某种节点测试,例如
父项:*
父项: