我有xml:
<?xml version="1.0" encoding="UTF-8"?>
<attachments>
<entry file="cewe_gw.jpg" name="cewe_gw.jpg"/>
<entry file="wp1827515.png" name="wp1827515.png"/>
</attachments>
我想获取列表文件?例如:
cewe_gw.jpg
wp1827515.png
发布于 2020-12-01 07:11:10
要选择任何元素或属性,可以使用XPath:
SELECT
xpath('//entry/@file',xml)
FROM mydata
这将返回一个文件属性数组。您可以使用unnest()
提取它们
SELECT
unnest(xpath('//entry/@file',xml))
FROM mydata
发布于 2020-12-01 07:05:01
如果你正在寻找Postgres解决方案,那么你可以使用xmltable
来实现:
select x.*
from the_table t
cross join xmltable('/attachments/entry'
passing t.the_xml_column
columns file text path '@name') as x
这将返回属性name
的值,如果需要file
属性,则需要将@name
更改为@file
https://stackoverflow.com/questions/65085930
复制相似问题