Topic
  • 2 replies
  • Latest Post - ‏2011-12-12T17:59:36Z by VV4H_mario_fernandes
VV4H_mario_fernandes
43 Posts

Pinned topic Xquery - Insert an element at second position in a xml string

‏2011-12-12T17:40:13Z |
Hi

The xml query below is inserting the xml fragement <requestor>quattl</requestor>
at the first position.
How can I insert it at the second position?
If that is not possible can I insert it after another element

This is how the end result should look like.
I am using DB2 9.7 on Linux.
<kasperSchema>
<TDSClient>
<workFlow>
<requestDate>20100116</requestDate>
<requestor>quattl</requestor>
</workFlow>
</TDSClient>
</kasperSchema>
update kasper.xml_client
set xml_client = xmlquery('copy $new := $XML_CLIENT
modify do insert <requestor>quattl</requestor> as first into $new/kasperSchema/TDSClient/workFlow
return $new' passing XML_CLIENT as "XML_CLIENT")
where
XMLEXISTS('$d/kasperSchema/TDSClient/kasperClient/client' passing xml_client as "d")

;
Updated on 2011-12-12T17:59:36Z at 2011-12-12T17:59:36Z by VV4H_mario_fernandes
  • VV4H_mario_fernandes
    43 Posts

    Re: Xquery - Insert an element at second position in a xml string

    ‏2011-12-12T17:42:21Z  
    Currently my xml looks like this

    <kasperSchema>
    <TDSClient>
    <workFlow>

    <requestor>quattl</requestor>
    <requestDate>20070306</requestDate>

    </workFlow>
    </TDSClient>
    </kasperSchema>
  • VV4H_mario_fernandes
    43 Posts

    Re: Xquery - Insert an element at second position in a xml string

    ‏2011-12-12T17:59:36Z  
    Currently my xml looks like this

    <kasperSchema>
    <TDSClient>
    <workFlow>

    <requestor>quattl</requestor>
    <requestDate>20070306</requestDate>

    </workFlow>
    </TDSClient>
    </kasperSchema>
    Use the after clause

    update kasper.xml_client
    set xml_client = xmlquery('copy $new := $XML_CLIENT
    modify do insert <requestor>quattl</requestor> after $new/kasperSchema/TDSClient/workFlow/requestDate
    return $new' passing XML_CLIENT as "XML_CLIENT")
    where
    XMLEXISTS('$d/kasperSchema/TDSClient/kasperClient/client' passing xml_client as "d")

    ;