Author |
Message
|
mqsi_guy |
Posted: Wed Aug 18, 2004 3:17 am Post subject: Re : Usage of FIELDNAME Function |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Aug 18, 2004 5:27 am Post subject: |
|
|
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 |
|
 |
EgilsJ.Rubenis |
Posted: Wed Aug 18, 2004 5:56 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Aug 18, 2004 6:11 am Post subject: |
|
|
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 |
|
 |
JT |
Posted: Wed Aug 18, 2004 7:03 am Post subject: |
|
|
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 |
|
 |
EddieA |
Posted: Wed Aug 18, 2004 9:06 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Wed Aug 18, 2004 9:22 am Post subject: |
|
|
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 |
|
 |
mqsi_guy |
Posted: Wed Aug 18, 2004 8:32 pm Post subject: |
|
|
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 |
|
 |
TDS_tds_tds |
Posted: Thu Aug 19, 2004 7:51 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Thu Aug 19, 2004 8:02 am Post subject: |
|
|
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 |
|
 |
Bhawesh |
Posted: Sun Aug 22, 2004 7:23 am Post subject: |
|
|
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 |
|
 |
|