PubxmlqueryXMLNode question

Hello.

I have a question about queryXMLNode (version 6.0.1).

Let’s say I pass the following node as input to queryXMLNode:

<?xml version=“1.0”?>
<doc>
<name>
<first>John</first>
<last>Smith</last>
</name>
<date>20040608</date>
</doc>

How do I extract the <name>…</name> element and assign it to an
object variable called NameNode?

If my XQL is “/doc”, then the following is assigned to NameNode:
<name>
<first>John</first>
<last>Smith</last>
</name>
<date>20040608</date>

If my XQL is “/doc/name”, then the following is assigned to NameNode:
<first>John</first>
<last>Smith</last>

What XQL query should I use to assign the following to NameNode?
<name>
<first>John</first>
<last>Smith</last>
</name>

Thanks.

Bob

If you do the XQL query /doc/name and set the result type to Object, you will get a node object with name as the root of the document.

You can verify this by mapping the result of the /doc/name query, which is an Object called the name of the query, into another queryXMLNode call with the XQL query /source(). You will see the document that contains the name element as the container.

If you send any XMLNode through xmlNodeToDocument the root of the document will be output as the pipeline key “document”. If you want it to be called “name” you can add a Map step to rename it.

HTH,
Fred

Hi Bob,
You can get a XMLstring for the specific node by using WQL
doc.name[0].source. It will give you desired output i.e.
<name>
<first>John</first>
<last>Smith</last>
</name>
You can convert it to node by using pub.xml:xmlStringToXMLNode service.
Fred’s query will also work fine to give you the node directly.
Cheers
Akash

Fred, Akash,

Thank you very much for your help.

I forgot to mention that my application
won’t know in advance the names of the
subelements of the doc element.

With your help, I see that I can
extract the first subelement of the
doc element using the following
XQL query:

/doc/*[0]/source()

This XQL query will return the
following:

<name>
<first>John</first>
<last>Smith</last>
</name>

Thanks again.

Bob

I would like to know if there is any way to introduce conditional statements in a WQL query. For example, if I have the following xml

<Collection>
<Object name=“name1” version=“001” handle=“0001”></Object>
<Object name=“name2” version=“001” handle=“0010”></Object>
<Object name=“name2” version=“002” handle=“0100”></Object>
<Object name=“name1” version=“002” handle=“1000”></Object>
</Collection>

What should I write as a WQL query if I want to get the handle of the Object which has version as “001” and the name as “name1”? Any help would be appreciated.

Thanks in Advance,
Pingaksha