代码之家  ›  专栏  ›  技术社区  ›  ashwnacharya

如何根据父节点的属性值查询XML节点

  •  1
  • ashwnacharya  · 技术社区  · 15 年前

    我有一个像这样的XML:

    <Library>
    <Author Name = "JRR Tolkien">
    <Book Title = "Lord Of the Rings" />
    <Book Title = "The Hobbit" />
    </Author>
    <Author Name = "JK Rowling">
    <Book Title = "Harry Potter and the Sorcerers Stone" />
    <Book Title = "Harry Potter and the Prisoner of Azkaban" />
    </Author>
    </Library>
    

    选择父“author”节点值为“jk rowling”的所有“book”节点的xpath是什么?

    1 回复  |  直到 15 年前
        1
  •  3
  •   Lasse Espeholt    15 年前

    这是最合理、最直观和最严格的,它选择了所有有 Author 哪一个 Name 属性是 'JK Rowling' 作为父母。以及 作者 也必须有 Library 作为父母。

    /Library/Author[@Name='JK Rowling']/Book