gpt4 book ai didi

xml - XPath id() 函数

转载 作者:数据小太阳 更新时间:2023-10-29 02:51:24 27 4
gpt4 key购买 nike

我找不到对 XPath 中的 id() 函数的任何好的解释。它有什么作用?如何使用它?

根据可用的描述,听起来它会给你一个节点的 id

所以我就这样玩了,但是报错了:

//bookstore/id(book)

然后变得有点狂热并尝试

//bookstore/book[name = id(book/@category)]

它没有返回错误,但没有命中。

有人可以为我、 future 的 Stack 粉丝和 Google 员工解释这个功能吗?

这是我正在使用的 XML:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J. K. Rowling</author>
<price>29.99</price>
</book>

<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

<book category="OPENSOURCE">
<title lang="en">Open Source</title>
<year>2003</year>
<price>39.95</price>
</book>

<book category="WEB">
<title lang="en">WEB</title>
<year>2012</year>
<price>21.99</price>
</book>

</bookstore>

最佳答案

看起来 based on the spec如果您定义了 unique IDs,您将只使用 id() 函数在你的 DTD 中。

The id function selects elements by their unique ID.

...

An element node may have a unique identifier (ID). This is the value of the attribute that is declared in the DTD as type ID.

我也遇到了这个 SO question讨论了 DTD 中的 ID 类型以及如何定义它。

关于xml - XPath id() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21733583/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com