我是XQuery的新手。
我有两个文件 - input.xml和config.xml,我希望能够搜索input.xml文件并检查所有config.xml soff是否在input.xml中
使用下面的示例,我想检查input.xml中是否存在soff = ABC和soff = DEF以及soff = GHI,如果在input.xml中找到所有三个,我想在配置中返回subscribergroup值.xml 没有硬编码
这是我的input.xml ......
<SOFF SOFNO="3732" NAME="ABC" ACTION="X">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
</OPNOKEY>
<PARMS QTY="3">
<PARM NAME="#NEW" VALUE="3" ACTION="A"/>
<PARM NAME="#NEW" VALUE="0" ACTION="R"/>
<PARM NAME="#OLD" VALUE="3" ACTION="X"/>
</PARMS>
<ATTRS QTY="0"/>
</SOFF>
<SOFF SOFNO="3735" NAME="DEF" ACTION="R">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
<OPNO>00104</OPNO>
</OPNOKEY>
<PARMS QTY="1">
<PARM NAME="INSTL" VALUE="GHI" ACTION="R"/>
</PARMS>
<ATTRS QTY="0"/>
</SOFF>
<SOFF SOFNO="2959" NAME="STB3" ACTION="R">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
<OPNO>00104</OPNO>
<OPNO>00105</OPNO>
</OPNOKEY>
<PARMS QTY="0"/>
<ATTRS QTY="0"/>
</SOFF>
<SOFF SOFNO="2958" NAME="JKL" ACTION="R">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
<OPNO>00104</OPNO>
<OPNO>00106</OPNO>
</OPNOKEY>
<PARMS QTY="0"/>
<ATTRS QTY="0"/>
</SOFF>
<SOFF SOFNO="2957" NAME="MNO" ACTION="R">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
<OPNO>00104</OPNO>
<OPNO>00107</OPNO>
</OPNOKEY>
<PARMS QTY="0"/>
<ATTRS QTY="0"/>
</SOFF>
<SOFF SOFNO="3349" NAME="PQR" ACTION="A">
<OPNOKEY>
<OPNO>00042</OPNO>
<OPNO>00045</OPNO>
<OPNO>00069</OPNO>
<OPNO>00103</OPNO>
<OPNO>00110</OPNO>
</OPNOKEY>
<PARMS QTY="0"/>
<ATTRS QTY="0"/>
</SOFF>
这是我的config.xml ...
<?xml version="1.0" encoding="UTF-8"?>
<subscriptionmappings>
<soff name="ABC">
<mandatorysoffs>
<soff name="DEF"/>
<soff name="GHI"/>
</mandatorysoffs>
<subscribergroup>sVOD-KidsSuite</subscribergroup>
</soff>
</subscriptionmappings>
据我所知,我似乎无法弄清楚如何检查where子句中的多个soff,我假设我需要一个for循环或类似的东西......
For $i in $config/mandatorysoffs/soff
where ($input/SOFF/@NAME = $config/soff/@name
and $input/SOFF/@NAME = $config/mandatorysoffs/soff/@name
and $input/SOFF/@NAME = $config/mandatorysoffs/soff/@name )
return $config/subscribergroup/text()
答案 0 :(得分:1)
You can just check for the occurrence of each soff
from the first document in the second document and then make sure that none of them are missing (i.e. false
):
xquery version "1.0";
let $chk-soffs := doc("config.xml")//soff/string(@name)
let $soffs := doc("input.xml")//SOFF/string(@name)
return
let $results := for $soff in $soffs
return
$chk-soffs = $soff
return
not($results = false())
or if you have access to a processor that supports XQuery 3.0:
xquery version "3.0";
let $chk-soffs := doc("config.xml")//soff/string(@name)
let $soffs := doc("input.xml")//SOFF/string(@name)
return
let $results := $soffs ! $chk-soffs = .
return
not($results = false())
答案 1 :(得分:1)
It appears that you want to return a <subscribergroup>
value for every <soff>
in your config for which the name of every child of <mandatorysoffs>
exists as a SOFF/@NAME
in the input. Using a universal quantifier in the where
clause:
for $s in $config/soff
where
every $n in $s/mandatorysoffs/soff/@name
satisfies ($n = $input/SOFF/@NAME)
return $s/subscribergroup/string()
Note that in your example GHI
is a PARM/@VALUE
so it still returns empty.