[英]How to find XML documents with certain attributes and nested elements?
I am searching for the regular expression that can find rows in an Oracle database. 我正在搜索可以在Oracle数据库中找到行的正则表达式。 The rows contain a string that looks like this:
这些行包含一个看起来像这样的字符串:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<characteristics>
<characteristic id="1001" mandatory="true" seq="1">
<wildcard/>
</characteristic>
<characteristic id="10001" mandatory="false" seq="1">
<value negation="false" seq="1">63</value>
</characteristic>
<characteristic id="10002" mandatory="false" seq="1">
<value negation="false" seq="1">64</value>
</characteristic>
<characteristic id="10051" mandatory="false" seq="1">
<value negation="false" seq="1">65</value>
</characteristic>
<characteristic id="10052" mandatory="false" seq="1">
<value negation="false" seq="1">66</value>
</characteristic>
<characteristic id="1010" mandatory="false" seq="100">
<wildcard/>
<value negation="false" seq="1">314</value>
</characteristic>
</characteristics>
The regular expression has to find all rows, that contain characteristics with special ids that contain a wildcard: 正则表达式必须查找所有包含特征的行,这些特征具有包含通配符的特殊ID:
<wildcard/>
For Example: I want to get all rows, that contain the characteristics with ids 1000 and 1001 with wildcard. 例如:我想获取所有包含具有通配符的ID为1000和1001的特征的行。 That means there must be the two strings
这意味着必须有两个字符串
<characteristic id="1001" ...
<wildcard/>
...
</characteristic>
and 和
<characteristic id="1000" ...
<wildcard/>
...
</characteristic>
in it. 在里面。 Thereby the two strings can be in different orders.
因此,两个字符串的顺序可以不同。
Assuming the data is stored as XMLtype 假设数据存储为XMLtype
select *
from t
where EXISTSNODE(doc,'/characteristics/characteristic[@id="1000"]/wildcard') = 1
and EXISTSNODE(doc,'/characteristics/characteristic[@id="1001"]/wildcard') = 1
;
Alternative syntax (as suggested by @Tomalak) 替代语法(如@Tomalak所建议)
select *
from t
where EXISTSNODE(doc,'/characteristics[characteristic[@id="1001"]/wildcard and characteristic[@id="1010"]/wildcard]') = 1
For learning purposes, in case the data is stored as string 出于学习目的,如果数据存储为字符串
select *
from (select xmltype(doc) as doc from t)
where EXISTSNODE(doc,'/characteristics/characteristic[@id="1000"]/wildcard') = 1
and EXISTSNODE(doc,'/characteristics/characteristic[@id="1001"]/wildcard') = 1
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.