Author |
Message
|
hellobond070 |
Posted: Thu Apr 29, 2010 7:50 pm Post subject: Splitting large XML file into individual XML |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
hi,
I have a XML which looks like below :
<Message>
<Child>abcde</Child>
<Child>sdlfkjl</Child>
<Child>defgh</Child>
</Message>
I have a break this message into individual outputs like below:
OUtput 1
<Message>
<Child>abcde></Child>
</Message>
OUtput2
<Message>
<Child>sdlfkjl></Child>
</Message>
Output3
<Message>
<Child>defgh</Child>
</Message>
Please let me know if this is possible to do without using a output message set by just using ATTACH and DETACH esql statements.
Also, if there is any other alternative way but without using any message set creation i.e. just by using ESQL code.
THanks. |
|
Back to top |
|
 |
fatherjack |
Posted: Fri Apr 30, 2010 6:19 am Post subject: Re: Splitting large XML file into individual XML |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Yeah. Exactly like you say....
hellobond070 wrote: |
just by using ESQL code. |
_________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Apr 30, 2010 6:52 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Looks like you could do this using a loop with a PROPAGATE statement.
Why did you think a message set might be required? Why did you think ATTACH and DETACH might be required? |
|
Back to top |
|
 |
hellobond070 |
Posted: Fri Apr 30, 2010 11:31 am Post subject: |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
Well if you just do a loop and propagate, it will propagate the full XML message and not just what is there in the loop. This was my understanding.
I then found a piece code as below ;
DECLARE i INTEGER 1;
DECLARE count INTEGER;
SET count = CARDINALITY(InputRoot.XMLNS.Invoice.Purchases."Item"[])
WHILE i <= count DO
--use the default tooling-generated procedure for copying message headers
CALL CopyMessageHeaders();
SET OutputRoot.XMLNS.BookSold.Item = InputRoot.XMLNS.Invoice.Purchases.Item[i];
PROPAGATE;
SET i = i+1;
END WHILE;
RETURN FALSE;
And yes Kimbert, I could achieve this using PROPAGATE.
Well message set can also help, provided we have it. Well ATTACH and DETACH is not solving my issue. I tried coding using this but it's not working.
Thanks for your support everyone. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Apr 30, 2010 11:37 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
hellobond070 wrote: |
Well ATTACH and DETACH is not solving my issue. I tried coding using this but it's not working. |
Not working how? Throwing an error or just not doing what you expect? Can you post further details?
Also here's a tip: don't use CARDINALITY. Use MOVE and LASTMOVE, it's far more efficient especially when you're traversing a large piece of XML as you are. If you reference element [i] as you are WMB will start at 1 each time and go through i-1 elements to find it. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
hellobond070 |
Posted: Sat May 01, 2010 8:50 am Post subject: |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
Well my problem is to convert
Quote: |
<Message>
<Child>abcde</Child>
<Child>sdlfkjl</Child>
<Child>defgh</Child>
</Message> |
to 3 output messages as posted before. I first use SET OutputRoot=InputRoot and assign the child array to a reference. Now I have no way to detach each of the child from the reference and attach it to the OutputRoot and keep propagating it through the out terminal.
I wish, I had the code which I deleted since the new code is working just fine without any issues. |
|
Back to top |
|
 |
mqjeff |
Posted: Sat May 01, 2010 9:09 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I wouldn't have copied everything to OutputRoot first, waste of effort.
It's really probably a bad idea to DETACH anything from input root, but if you really wanted to do it, that's how I'd do it. DETACH from InputRoot, ATTACH to OutputRoot, Propagate.
But other than switching InputRoot.XMLNS.Invoice.Purchases.Item[i] to use a REFERENCE variable, and using the XMLNSC parser instead of the XMLNS parser, there's nothing wrong with the code you have and it's the preferable method. |
|
Back to top |
|
 |
hellobond070 |
Posted: Sat May 08, 2010 3:29 pm Post subject: |
|
|
 Centurion
Joined: 18 Nov 2009 Posts: 118
|
Well yes Mqjeff.
I have finally converted the pasted piece of code to my requirement using XMLNSC.
I am really not sure whether we can use DETACH on the InputRoot. It's like manipulating the Input XML which according to me should not be possible. What I do know is that we can mess around with the outputRoot once we do SET OutputRoot = InputRoot in this case scenario.
I found the below text in infocenter which tells us more about usage of DETACH
Quote: |
The following example illustrates how to use the ATTACH statement, together with the DETACH statement described in DETACH statement, to modify a message structure. The dynamic reference supplied to the DETACH statement must point to a modifiable message tree such as Environment, LocalEnvironment, OutputRoot, OutputExceptionList, or InputLocalEnvironment. |
|
|
Back to top |
|
 |
|