Highlighted

Merging to xml variables with identical structure

kc

07-01-2009

Hi all,



I have two xml variables with identical structure, and I need to merge these two. How can I do this?



Thanks in advance



Sincerely

Kim

Replies

Highlighted

Jasmin_Charbonn

07-01-2009

What do you mean by merging the two xml?



Copy the different elements of each node into the same node structure in the other xml?



You would have to use the Script service or a custom component to do that?



Jasmin
Highlighted

kc

07-01-2009

Hi againn,



An example might help here:



I hvae two forms which share the same "master schema" that contains the superset of the elements of the two forms.



So I have this:



form1

Name

Address

...

\form1

form2

Amount

Creditcard

...

\form2



So for example I have an xml variable where one person has filled out all fields for form1 and now I want to put in these into another xml variable where another person (in parallel) has filled out all info in form2. How can this be done without making a assignment to each element one at a time.



E.g. I don't wnat to do the following:



myXml1/form1/Name = myXml2/form1/Name

myXml1/form1/Address = myXml2/form1/Address



Can I do this in just one step?



Sincerely

Kim
Highlighted

Jasmin_Charbonn

07-01-2009

You would have to group you elements.



For example you could have



form1

Section1

Name

Address

/Section1

/form1



form1

Section2

Amount

CreditCard

/Section2

/form1



That way you can do myXML1/form1/Section1 = myXML2/form1/Section1



Otherwise you need to do it one by one or use a custom component.



Jasmin
Highlighted

parth_pandya

07-01-2009

Hi Kim,

Do you know xslt or xquery?

I think doing the xml transformation via xslt or xquery would be an easier alternate for you compared to custom component or script.



Parth
Highlighted

kc

09-01-2009

Hi again,



Thanks for the input - I got it to work by using your suggestion Jasmin.



To Parth: I am not aware how I can use XQuery with LC, can you send a link to where I could find more on this. Also I would like to know more on the XSLT transformations on xml files (I have not yet used them actively in my solutions).



If anyone has info (links or anything) on these issues I would like to hear about it 🙂



Thanks in advance



Sincerely

Kim
Highlighted

parth_pandya

11-01-2009

Hi Kim,

To use XQuery with LC, you should install XQuery component as regular dsc and put it's operation as a step in your orchestration.

Example of it can be found at http://manly.avoka.com.au/confluence/display/Public/Transforming+XML+Documents

Have a look at www.w3schools.com for the xslt and xquery tutorials. XSLT and XQuery are really handy to know when you have to work with xml frequently.

Cheers,

Parth
Highlighted

Aditya_S_

30-01-2009

I have a similar issue. The only difference is I have repeating subforms.<br /><br />XML1 contains non repeating subforms. XML2 contains repeating subforms.<br /><br />I would like to add XML2<br /><br /><form1><br /> <CompetencyDetails> <br /> <employee_firstname>Joe</employee_firstname> <br /> <employee_lastname/> <br /> </CompetencyDetails> <br /> <CompetencyDetails> <br /> <employee_firstname>Bob</employee_firstname> <br /> <employee_lastname/> <br /> </CompetencyDetails><br /> </Details><br /></form1> <br /><br />to XML1<br /><br /><form1><br /> </CompetencyDetails><br /> <Details> <br /> <review_from>01122009</review_from> <br /> <review_to>12122009</review_to> <br /> <evaluator_firstname>Sam</evaluator_firstname> <br /> <evaluator_lastname>Evaluator</evaluator_lastname> <br /> </Details><br /><form1><br /><br />Using SetValue I could not get <br /><br /><b>/process_data/xml/form1/CompetencyDetails=/process_data/xml2/form1/CompetencyDetails[*]</b><br /><br />to work. Any help will be highly appreciated.
Highlighted

Jasmin_Charbonn

30-01-2009

If you want to merge and have the following result



Joe



Bob



01122009
12122009
Sam
Evaluator



Then you could probably do something like

/process_data/xml2/form1/Details=/process_data/xml1/form1/Details/*

You want to avoid copying the content from the xml that has repeating nodes. In my example I keep the xml with the two repeating nodes (CompetencyDetails) intact and just copy the content of Details over.

Jasmin
Highlighted

Aditya_S_

01-02-2009

Ha!! I never thought of that. Thank you Jasmin !!



You saved me a lot of code as I was planning to implement in a custom script.



Aditya