Java api query nested elements help

Hello we have an xml structure like this :

<A
















/A>

Where elements, can be repeated in this structure. Where a , b, or c can take values from 1 to n.

In this way we are wondering if it’s posible to make a query where asking only for L, M, I or F to have a value X and return only the related parents and that complish with the searched value/s descarting the other ones ( ) that are not acomplishing the search condition.

Thanks in advance.

Hi,

you are somewhat vague on the expected result, so I can only guess that the following query produces what you want to see


for $d in collection("ino:etc")/A
return ($d/*[starts-with(local-name(.),"D") and F="X"],
$d/*/*[starts-with(local-name(.),"G") and I="X"],
$d/*/*/*[starts-with(local-name(.),"J") and (L="X" or M="X")])

If applied to the input


<A><B/><C/><D1><E/><F>X</F><G1><H/><I>X</I><J1><K/><L/><M>X</M><N/></J1></G1></D1><D2><E/><F/><G1><H/><I>X</I><J1><K/><L/><M/><N/></J1></G1>

<G2><H/><I>Y</I><J1><K/><L/><M/><N/></J1></G2></D2><D3><E/><F/><G1><H/><I/><J1><K/><L/><M/><N/></J1><J2><K/><L/><M/><N>X</N></J2></G1></D3></A>

it produces the output


<D1>
<E/>
<F>X</F>
 <G1>
<H/>
<I>X</I>
 <J1>
<K/>
<L/>
<M>X</M>
<N/>
</J1>
</G1>
</D1>
 <G1>
<H/>
<I>X</I>
 <J1>
<K/>
<L/>
<M>X</M>
<N/>
</J1>
</G1>
 <G1>
<H/>
<I>X</I>
 <J1>
<K/>
<L/>
<M/>
<N/>
</J1>
</G1>
 <J1>
<K/>
<L/>
<M>X</M>
<N/>
</J1>

Regards

Harald

Thanks for your answer, I did not meant to be vague in this way I’ll try to be more precise
Input xml:

123 29 I>30</I 32 33 34 35 37 38 39 40 6 I>48</I 50 51 52 53 55 56 57 17 555 60 I>61</I 62 63 64 65 67 68 69 70 71 I>72</I 73 74 75 76 77 78 79 80 223 6 I>7</I 9 10 11 12 14 15 16 17 19 20 21 17

If I ask for F=123 and H=6 and N=17 the espected output should be :

123 6 I>48</I 55 56 57 17

Notice that the following elements or nodes have been removed : D2 and G1 and J1 from xml structure D1 of the element or node A1
Is this possible?

Thanks in advance,
Enric

Hi

try


declare function local:filter ($in as node()) as node() {
if (starts-with(local-name($in),"D") and not ($in[F=123 and */H=6 and */*/N=17])
    or starts-with(local-name($in),"G") and not ($in[H=6 and */N=17])
    or starts-with(local-name($in),"J") and not ($in[N=17])
) then ()
else
element {local-name($in)} {$in/@*, 
for $node in $in/* return if ($node/*) then local:filter($node) else $node}
}
for $doc in collection("ino:etc")/*
let $d:=$doc/*[starts-with(local-name(.),"D") and F=123 and */H=6 and */*/N=17]
where $d
return local:filter($doc)

Regards

Harald

Hi, Harald thanks for your help and for being so patient. I am just a beginner with XQuery.

I’ve tried the following query:

declare function local:filter ($in as node()) as node() {
if (starts-with(local-name($in),“D”) and not ($in[F=123 and /H=6 and //N=17])
or starts-with(local-name($in),“G”) and not ($in[H=6 and /N=17])
or starts-with(local-name($in),“J”) and not ($in[N=17])
) then ()
else
element {local-name($in)} {$in/@
,
for $node in $in/
return if ($node/) then local:filter($node) else $node}
}
for $doc in input()/A
let $d:=$doc/
[starts-with(local-name(.),“D”) and F=123 and */H=6 and //N=17]
where $d
return local:filter($doc)

Returned error :

<ino:messagetext ino:code=“INOXQE6352”>XQuery parsing error</ino:messagetext>
ino:messageline
Syntax Error at line 1, column 9: found “function” when expecting any of: “or”, “and”, “div”, “mod”, " *", “intersect”, “union”, “except”, “/”, “//”, “=”, “!=”, “<=”, “>=”, “eq”, “ne”, “gt”, “ge”, “lt”, “le”, "< ", “>”, “-”, “+”, “=>”, “|”, “(”, “[”, “,”, “sort”, “stable”
</ino:messageline>
</ino:message>

Seems to fail on method starts-with used in function local:filter.
I’ve executed the following xquery:

for $doc in input()/A
let $d:=$doc/*[starts-with(local-name(.),“D”) and F=123 and */H=6 and //N=17]
where $d
return $doc

And this worked fine. Any idea about this?

Thanks in advance

Hi,

this looks like you do not have Tamino v4.4 installed (but maybe V4.2). Please check the version of your system

regards

harald

Hi Harald, we are working with tamino version 4.2.1.7 . Is it posible to execute this kind of queries with this versi

Hi,

this kind of query does not work with 4.2. I suggest you to upgrade to v4.4

Regards

harald