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 » Re : Usage of FIELDNAME Function

Post new topic  Reply to topic
 Re : Usage of FIELDNAME Function « View previous topic :: View next topic » 
Author Message
mqsi_guy
PostPosted: Wed Aug 18, 2004 3:17 am    Post subject: Re : Usage of FIELDNAME Function Reply with quote

Newbie

Joined: 24 Nov 2003
Posts: 9

Hi,

I have a particular requirement in XML to MRM transformation whereby the roottag of the XML message identifies the type of message and corresponding transformation that needs to be done.

Assuming two XML messages with roottag A and B,

Message1
-----------

<A>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</A>

Message2
-----------

<B>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</B>

the XML roottags A and B will identify the type of message and will determine corresponding routing and transformation.

I have been trying to identify the roottag by using the function FIELDNAME("InputBody".*[1]). But the input message might also come in the form ( the XML version and encoding information included).

<?xml version="1.0" encoding="UTF-8"?>
<A>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</A>

Similarly for the message with Roottag B. To identify the roottag, I am trying to use FIELDNAME ("InputRoot"."XML".*[LAST] and FIELDNAME ("InputBody".*[2]), but without any success.

The trace shows the both FIELDNAME ("InputRoot"."XML".*[LAST]) and FIELDNAME ("InputBody".*[2]) being evaluated to ' '.

Wondering if there is any other way of handling this scenario.

Any help is highly appreciated

Regards,
mqsi_guy
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Aug 18, 2004 5:27 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You could always just see if InputRoot.XML.A or InputRoot.XMl.B exists...
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
EgilsJ.Rubenis
PostPosted: Wed Aug 18, 2004 5:56 am    Post subject: Reply with quote

Acolyte

Joined: 18 Nov 2002
Posts: 63
Location: Germany, Alfeld

Hi, i guess there are different ways to check the tag:

I would check the cardinality:
If cardinality(InputRoot.XML.A[]) > 0 Then .......
If cardinality(InputRoot.XML.B[]) > 0 Then .......

cheers Egils
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Wed Aug 18, 2004 6:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I think checking to see if the tag itself IS NULL is more efficient.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
JT
PostPosted: Wed Aug 18, 2004 7:03 am    Post subject: Reply with quote

Padawan

Joined: 27 Mar 2003
Posts: 1564
Location: Hartford, CT.

I agree with Jeff's suggestion, however your original attempt should have worked.
Code:
IF FIELDNAME(InputRoot.XML.[<]) = 'A' THEN
......
ELSE
   IF FIELDNAME(InputRoot.XML.[<]) = 'B' THEN
....

Note: although the keyword LAST is still supported it has been deprecated and replaced with <
Back to top
View user's profile Send private message
EddieA
PostPosted: Wed Aug 18, 2004 9:06 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

One of the problems with "anonymous" references is that any "white space" you have in the XML is also present in the tree. This can cause references to fail. You can also check FIELDTYPE to ensure that the field you are referenceing is actually a TAG.

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
jefflowrey
PostPosted: Wed Aug 18, 2004 9:22 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

EddieA wrote:
One of the problems with "anonymous" references is that any "white space" you have in the XML is also present in the tree. This can cause references to fail. You can also check FIELDTYPE to ensure that the field you are referenceing is actually a TAG.


Yeah. Checking the tag based on name is a lot simpler to code.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mqsi_guy
PostPosted: Wed Aug 18, 2004 8:32 pm    Post subject: Reply with quote

Newbie

Joined: 24 Nov 2003
Posts: 9

Hi,

Thanks for all the replies.

I think the post gave a wrong impression regarding the problem. Let me see if I can put it in a better way.

There are multiple XML message types coming to the input queue and the decision of the type of transformation is based on the message type identified by the roottag.

Message1
-----------

<A>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</A>

Message2
-----------

<B>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</B>

......
......
so on

I am identifying the message type (checking for the roottag) by using the function FIELDNAME("InputBody".*[1]) . This works perfectly fine.

There is also a probability the XML message might contain <?xml version="1.0" encoding="UTF-8"?> before the actual XML data.

<?xml version="1.0" encoding="UTF-8"?>
<A>
<Header>
................
................
</Header>
<Body>
..............
..............
</Body>
</A>

In this case
Code:

                                         (0x1000010)XML        = (
                                           (0x5000018)XML         = (
                                             (0x6000011) = '1.0'
                                             (0x6000012) = 'UTF-8'
                                           )
                                           (0x6000002)            = '
                                       '
                                           (0x1000000)A = (
                                             (0x2000000)       = '
                                          '
                                             (0x1000000)Header = (
                                               (0x2000000)                   = '
                                             '
                                               (0x1000000)MessageType        = (
                                                 (0x2000000) = 'TEST'
                                               )
                                               (0x2000000)                   = '
                                             '
                                               (0x1000000)Time               = (
                                                 (0x2000000) = '151801'
                                               )
                                               (0x2000000)                   = '
                                             '
                                               (0x1000000)Date               = (
                                                 (0x2000000) = '20040623'
                                               )


FIELDNAME("InputBody".*[1]) will evaluate to 'XML'. Hence tried using FIELDNAME ("InputRoot"."XML".*[LAST] and FIELDNAME ("InputBody".*[2]) and FIELDNAME ("InputBody".*[LAST]) to identify the Roottag. This does not seem to work.

FIELDNAME ("InputRoot"."XML".*[LAST] , FIELDNAME ("InputBody".*[2]) and FIELDNAME ("InputBody".*[LAST]) are being evaluated to ' ' whereas I was expecting it to evaluate to the roottag (A for the above mentioned case).

Any clue where it is going wrong ?

Regards,
mqsi_guy
Back to top
View user's profile Send private message
TDS_tds_tds
PostPosted: Thu Aug 19, 2004 7:51 am    Post subject: Reply with quote

Novice

Joined: 31 Jul 2003
Posts: 16

hi mqsi_guy,
as you see from your trace :
Code:

                                             (0x1000010)XML        = (
                                           (0x5000018)XML         = (
                                             (0x6000011) = '1.0'
                                             (0x6000012) = 'UTF-8'
                                           )
                                           (0x6000002)            = '
                                       '
                                           (0x1000000)A = (
                                             (0x2000000)       = '
                                          '
 


Under the root XML it has 2 childs one is XML declaration info and another is ''.
So in your case,
Quote:
FIELDNAME ("InputRoot"."XML".*[LAST])
will always be evaluated as ''
If the message is put to the input queue through a file, there are chances that you have a line feed after the
Code:
<?xml version="1.0" encoding="UTF-8"?>
yaada yaada declaration. If it is a file do an "od -cx <filename>" on the file .... you can see linefeed character.

Unfortunately WMQI considers the line feeds in XML as a node and parses it as child/sibling/parent which ever is appropriate.

what you can do in this case is,
Code:

declare curRef char;
DECLARE a reference to InputRoot.XML;
MOVE that reference to FIRSTCHILD.
IF (FIELDNAME(myRef) NOT IN  ('A','B')) THEN
       MOVE myRef NEXTSIBLING; -- this is to pass the XML decl node
       
END IF;

SET curRef =  FIELDNAME(myRef) ;
obviously, curRef gives u either A or B
in the nxt steps do what ever you need to do with body of A or B

Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Aug 19, 2004 8:02 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

That's a bunch of complicated code that is relatively hard to understand.

If you want to check if your XML Root tag is 'A', then the simplest, fastest, easiest to understand piece of code is
Code:
IF InputRoot.XML.A IS NOT NULL THEN

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Bhawesh
PostPosted: Sun Aug 22, 2004 7:23 am    Post subject: Reply with quote

Newbie

Joined: 22 Oct 2002
Posts: 8
Location: NJ-NY-CT (USA)

I cannot verify this at this time, and since you have already tested various ways to accomplish that, would you also check if this piece of code works after inserting it at appropriate place in appropriate way.

FIELDNAME(InputBody.(XML.Element)[1])
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 » Re : Usage of FIELDNAME Function
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.