ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » ESQL to create a new tag nested in preexisting xml

Post new topic  Reply to topic
 ESQL to create a new tag nested in preexisting xml « View previous topic :: View next topic » 
Author Message
sebastian
PostPosted: Mon Apr 19, 2004 8:47 am    Post subject: ESQL to create a new tag nested in preexisting xml Reply with quote

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
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Mon Apr 19, 2004 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message
sebastian
PostPosted: Mon Apr 19, 2004 9:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Missam
PostPosted: Mon Apr 19, 2004 10:18 am    Post subject: Reply with quote

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
View user's profile Send private message
EddieA
PostPosted: Mon Apr 19, 2004 10:23 am    Post subject: Reply with quote

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
View user's profile Send private message
fschofer
PostPosted: Mon Apr 19, 2004 10:47 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Mon Apr 19, 2004 10:53 am    Post subject: Reply with quote

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
View user's profile Send private message
sebastian
PostPosted: Tue Apr 20, 2004 4:10 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
EddieA
PostPosted: Tue Apr 20, 2004 6:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Missam
PostPosted: Tue Apr 20, 2004 7:07 am    Post subject: Reply with quote

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
View user's profile Send private message
sebastian
PostPosted: Wed Apr 21, 2004 7:27 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
EddieA
PostPosted: Wed Apr 21, 2004 8:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » ESQL to create a new tag nested in preexisting xml
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.