Jay1927
Jay1927

Reputation: 35

XQuery: Inserting a XML document into a second XML document

I have 2 separate XML files as shown below. The first XML document only contains a single tag.

<office>HeadOffice</office>

And the second document:

 <Data>
    <location>
        <city>London</city>
        <country>England</country>
        <region>Europe</region>
    </location>
    <services>
        <consulting>SAP</consulting>
        <industry>Oil</industry>
    </services>
 </Data>

What I would like to do is to insert the first document (the single tag) into the second XML document so that it results as below. Please note the first document is only inserted inside the tag.

 <Data>
    <location>
        <city>London</city>
        <country>England</country>
        <region>Europe</region>
        <office>HeadOffice</office>
    </location>
    <services>
        <consulting>SAP</consulting>
        <industry>Oil</industry>
    </services>
 </Data>

Unfortunately I am not able to use the XQuery Update Facility specification for this, i.e I can't use:

insert node<office>HeadOffice</office> into $data/location

How would I go about doing this? I can't seem to find anything on this besides using the "insert node" method. Any help would be greatly appreciated.

Cheers Jay

Upvotes: 2

Views: 70

Answers (1)

adamretter
adamretter

Reputation: 3517

You can write a typeswitch transformation which will combine the two together into a new document in the manner you desire. For examples take a look at: https://en.wikibooks.org/wiki/XQuery/Typeswitch_Transformations

Upvotes: 2

Related Questions