如何从 Oracle table clob 列中查找 xml 文件中所有元素和属性的列表?
How to find list of all elements&attributes in a xml file from a Oracle table clob column?
我试图在 XML 文件中查找所有标签(包括其 XPATH),该文件位于 Oracle table 的 CLOB 列中。你能提供一个查询吗?
可以使用 XSL 样式生成唯一标签列表 sheet。
首先创建一个简单的 table,其中 XML 存储为 CLOB,使用随机 sample XML:
create table sample_xml(id number, some_xml clob);
insert into sample_xml values(1, q'[<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
</book>
</catalog>]');
现在使用XMLTRANSFORM
to convert the XML to a distinct set of tags, using the XML style sheet from this question:
select xmltransform(
xmltype(some_xml),
xmltype('<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*" />
<xsl:key name="kElemByName" match="*" use="name(.)"/>
<xsl:template match="
*[generate-id()
=
generate-id(key(''kElemByName'', name(.))[1])
]">
<xsl:value-of select="concat(name(.), '''||chr(38)||'#xA;'')"/>
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>')) tags
from sample_xml;
TAGS
----
catalog
book
author
title
使用regexp_substr
拆分字符串可以得到结果one-line-at-a-time:
select regexp_substr(replace(tags, chr(10), ','),'[^,]+', 1, level) from
(
... insert large query here
)
connect by regexp_substr(replace(tags, chr(10), ','),'[^,]+', 1, level) is not null;
要同时查看属性,请查看链接的问题,它还包括用于获取属性的 XML 样式 sheets。
我试图在 XML 文件中查找所有标签(包括其 XPATH),该文件位于 Oracle table 的 CLOB 列中。你能提供一个查询吗?
可以使用 XSL 样式生成唯一标签列表 sheet。
首先创建一个简单的 table,其中 XML 存储为 CLOB,使用随机 sample XML:
create table sample_xml(id number, some_xml clob);
insert into sample_xml values(1, q'[<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
</book>
</catalog>]');
现在使用XMLTRANSFORM
to convert the XML to a distinct set of tags, using the XML style sheet from this question:
select xmltransform(
xmltype(some_xml),
xmltype('<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*" />
<xsl:key name="kElemByName" match="*" use="name(.)"/>
<xsl:template match="
*[generate-id()
=
generate-id(key(''kElemByName'', name(.))[1])
]">
<xsl:value-of select="concat(name(.), '''||chr(38)||'#xA;'')"/>
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>')) tags
from sample_xml;
TAGS
----
catalog
book
author
title
使用regexp_substr
拆分字符串可以得到结果one-line-at-a-time:
select regexp_substr(replace(tags, chr(10), ','),'[^,]+', 1, level) from
(
... insert large query here
)
connect by regexp_substr(replace(tags, chr(10), ','),'[^,]+', 1, level) is not null;
要同时查看属性,请查看链接的问题,它还包括用于获取属性的 XML 样式 sheets。