Author |
Message
|
sebastian |
Posted: Mon Apr 19, 2004 8:47 am Post subject: ESQL to create a new tag nested in preexisting xml |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
Dear MQSeries Experts:
I am searching for ESQL to take an incoming xml document and nest within it a new tag and attribute. I am using a compute node in MQ integrator v2.1.
Below is an example of what I am trying to do....
I have incoming:
<?xml version="1.0"?">
<root>
<country>
<country1>united states</country1>
<country2>japan</country2>
<country3>germany</country3>
</country>
</root>
and I want to convert this into...
<?xml version="1.0"?">
<root>
<planet_earth BEGIN="planets">
<country>
<country1>united states</country1>
<country2>japan</country2>
<country3>germany</country3>
</country>
</planet_earth>
</root>
Any feedback is greatly appreciated,
Sebastian _________________ sebastian signature |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Apr 19, 2004 9:06 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Code: |
declare thisRef reference to InputRoot.XML.root.country;
move thisRef to firstchild of OutputRoot.XML.root.planet_earth;
set OutputRoot.XML.root.planet_earth.(XML.Attrib)"BEGIN"='planets'; |
Or thereabouts. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sebastian |
Posted: Mon Apr 19, 2004 9:30 am Post subject: |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
Jeff:
I get a syntax error on the line:
move thisRef to Firstchild of OutputRoot.XML.root.planet_earth;
I'm still a bit new to ESQL so I do not know what is erroring out. I will dig but would appreciate any clarification anyone could offer.
thanks,
Sebastian _________________ sebastian signature |
|
Back to top |
|
 |
Missam |
Posted: Mon Apr 19, 2004 10:18 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Code: |
SET OutputRoot.XML.root."planet_earth".country = InputRoot.XML.root.country;
SET OutputRoot.XML.root."planet_earth".(XML.Attribute)BEGIN = 'planets'; |
hope these two lines of code does what you want |
|
Back to top |
|
 |
EddieA |
Posted: Mon Apr 19, 2004 10:23 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Doesn't MOVE just update a REFERENCE pointer. I don't think you can use it to move 'data'.
Isn't it the DETACH and ATTACH commands that are needed.
Code: |
SET OutputRoot = InputRoot;
DECLARE myREF REFERENCE TO OutputRoot.XML."root".country;
DETACH myREF;
SET OutputRoot.XML."root".planet_earth.(XML.Attrib)"BEGIN"='planets';
ATTACH myREF TO OutputRoot.XML."root".planet_earth AS FIRSTCHILD;
|
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
fschofer |
Posted: Mon Apr 19, 2004 10:47 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hmm,
next time if have to be faster
For a ESQL beginner i think its easier first to use
oldstyle ESQL without references (i know references are faster) like:
Code: |
SET OutputRoot.XML.root.planet_earth.(XML.Attrib)"BEGIN"='planets';
SET OutputRoot.XML.root.planet_earth.country = InputRoot.XML.root.country; |
With references this could work (untested):
Code: |
SET OutputRoot = InputRoot;
DECLARE myREF REFERENCE TO OutputRoot.XML.root.country;
DETACH myREF;
SET OutputRoot.XML.root.planet_earth.(XML.Attrib)"BEGIN"='planets';
ATTACH myREF TO OutputRoot.XML.root.planet_earth AS LASTCHILD; |
Greetings
Frank |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Apr 19, 2004 10:53 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
EddieA wrote: |
Doesn't MOVE just update a REFERENCE pointer. I don't think you can use it to move 'data'. |
Is it Monday yet?  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sebastian |
Posted: Tue Apr 20, 2004 4:10 am Post subject: |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
The ESQL that Eddie sent worked fine for the simplified example that I sent but I had problems with the actual data I'm using. THe data structure input looks like the following:
INPUT:
<?xml version="1.0" encoding="iso-8859-1"?>
<HEADER_TAG>
<EDI_DC40>
</EDI_DC40>
<E1STZUM>
</E1STZUM>
<E1STZUTH repeating="yes">
<E1SZUTL repeating="yes">
</E1SZUTL>
</E1STZUTH>
<E1MASTM repeating="yes">
</E1MASTM>
<E1STKOM repeating="yes">
</E1STKOM>
<E1STPOM repeating="yes">
</E1STPOM>
</HEADER_TAG>
DESIRED OUTPUT:
<?xml version="1.0" encoding="iso-8859-1"?>
<HEADER_TAG>
<NEW_TAG BEGIN="1">
<EDI_DC40>
</EDI_DC40>
<E1STZUM>
</E1STZUM>
<E1STZUTH repeating="yes">
<E1SZUTL repeating="yes">
</E1SZUTL>
</E1STZUTH>
<E1MASTM repeating="yes">
</E1MASTM>
<E1STKOM repeating="yes">
</E1STKOM>
<E1STPOM repeating="yes">
</E1STPOM>
</NEW_TAG BEGIN>
</HEADER_TAG>
WHAT I GET NOW:
<?xml version="1.0" encoding="iso-8859-1"?>
<HEADER_TAG>
<E1STZUM>
</E1STZUM>
<E1STZUTH repeating="yes">
<E1SZUTL repeating="yes">
</E1SZUTL>
</E1STZUTH>
<E1MASTM repeating="yes">
</E1MASTM>
<E1STKOM repeating="yes">
</E1STKOM>
<E1STPOM repeating="yes">
</E1STPOM>
<NEW_TAG BEGIN="1">
<EDI_DC40>
</EDI_DC40>
</NEW_TAG>
</HEADER_TAG>
I am looking at the ESQL v2.1 reference manual and on page 50 it lists limitations of the attach tahe look similar to the problem I am having. Is there an alternate command that I could use to make this work?
Any feedback is appreciated,
Sebastian _________________ sebastian signature |
|
Back to top |
|
 |
EddieA |
Posted: Tue Apr 20, 2004 6:34 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
*** Warning *** Not Tested. *** Warning ***
Code: |
-- Copy Headers only
-- Build ?XML
-- Build NEW_TAG
DECLARE InputRec REFERENCE to InputBody.HEADER_TAG.*[1];
WHILE LASTMOVE (InputRec) DO
IF FIELDTYPE(InputRec) = XML.tag THEN
SET OutputRoot.XML.HEADER_TAG.{FIELDNAME(InputRec)} = InputRec;
END IF;
MOVE InputRec NEXTSIBLING;
END WHILE;
|
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
Missam |
Posted: Tue Apr 20, 2004 7:07 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
I guess there should be a move statement before using it in while loop
Eddie's Code
Code: |
-- Copy Headers only
-- Build ?XML
-- Build NEW_TAG
DECLARE InputRec REFERENCE to InputBody.HEADER_TAG.*[1];
MOVE InputRec TO InputBody.HEADER_TAG.*[1];
WHILE LASTMOVE (InputRec) DO
IF FIELDTYPE(InputRec) = XML.tag THEN
SET OutputRoot.XML.HEADER_TAG.{FIELDNAME(InputRec)} = InputRec;
END IF;
MOVE InputRec NEXTSIBLING;
END WHILE;
|
|
|
Back to top |
|
 |
sebastian |
Posted: Wed Apr 21, 2004 7:27 am Post subject: |
|
|
 Centurion
Joined: 12 Nov 2003 Posts: 110 Location: Philadelphia
|
I get a syntax error on the {FIELDNAME(InputRec)}=InputRec; command. The red cursor for syntax errors lines up in front of FIELDNAME.
The ESQL reference manual shows the syntax on page 94 and it looks correct to me.
Any suggestions?
Seb _________________ sebastian signature |
|
Back to top |
|
 |
EddieA |
Posted: Wed Apr 21, 2004 8:24 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Yes, apply CSD03 or higher, which is where the {...} dynamic references were introduced.
Also, I'm not sure why Sam added that MOVE in there. The reference pointer was already set by the DECLARE.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
|