gpt4 book ai didi

xml - 在 postgresql 数据库中使用 xpath 在 xml 中搜索

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

我在 Postgresql 中有一个数据库,我在其中放置了一些用 xml 编写的文档。我想使用 XPath 搜索它们,但我的代码不工作。文件是这样的:

<?xml version="1.0" standalone="yes"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
....
<revisionDesc>
<listChange>
<change when="2017-01-11+01:00" who="person"/>
</listChange>
</revisionDesc>
</teiHeader>
...
</TEI>

我正在尝试获取 change 元素的 when 属性。到目前为止我的代码:

SELECT 

xpath('TEI/n:teiHeader/n:revisionDesc/n:listChange/n:change[@when]/text()',

xml_document , '{{n,http://www.tei-c.org/ns/1.0}}')

FROM xml_table where xml_id = 5;

它给了我这样的空结果:{} 我不明白为什么

最佳答案

如果您想引用根元素,您需要在您的xpath 查询前添加/。或者,您可以省略 n:TEI,因为 xpath() 函数将搜索相对于根元素的结果(在 xpath 术语中,即当前节点)。

即这些 xpath 查询将找到 when 属性的值:

/n:TEI/n:teiHeader/n:revisionDesc/n:listChange/n:change/@when
n:teiHeader/n:revisionDesc/n:listChange/n:change/@when

关于xml - 在 postgresql 数据库中使用 xpath 在 xml 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41634096/

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