Author |
Message
|
ayanc |
Posted: Thu Dec 07, 2006 5:48 pm Post subject: Changing case of XML tags |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi,
I am receiving an input XML message having small case tag values. The output xsd is in upper case. Hence although I need not change the data of the message, I need to change the tag values into upper case.
However there is a catch. These tags may contain attributes. The data and attribute names must remain as it is in the input message.
I have tried the following two methods:
Method 1:
1. Copied the input message to output tree.
2. Recursively traversed the message in output tree and used a similar statement as - SET Out_Cursor[NAME] = UPPER(In_Cursor). (Cursors are reference variables).
However strange it may seem, the elements in the message in output queue remains in small case although traces taken before and after the output node shows the elements to be in upper case. Though this may be a case to ponder, it poses a new problem. All tags having attributes are also converted into upper case names (as per the trace file of course).
However I am at a loss to determine how to stop my attribute names from changing to upper case.
Method 2:
1. Copied the input message to Environment tree.
2. Recursively traversed the message in output tree and used a similar statement as - SET Out_Cursor[NAME] = UPPER(In_Cursor). (Cursors are reference variables).
This time I get the message converted into upper case tag names.
However, in this approach all my attributes are converted into child elements. That seems to be justified as the Environment variables are after all not XML parsers. ( )
Is there any solution to the above problem?
I am using MB 5.0 CSD 05
Thanx. |
|
Back to top |
|
 |
fat_tony |
Posted: Fri Dec 08, 2006 12:05 am Post subject: |
|
|
Novice
Joined: 02 Dec 2006 Posts: 15
|
Mehtod 1:
Code: |
IF FIELDTYPE(Out_Cursor) = XML.Element or........
THEN
...... |
This is a little messy though - not sure exactly how many field types you'd have to cater for. Obviously you could reverse the logic e.g. not = XML.Attribute. Look it up and see if it suits you.
You say your output xsd requires upper case - so you have a schema? Message Sets? |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Dec 08, 2006 3:08 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You can use TYPE on the MOVE statement to indicate that you only want to move to the next or previous XMLNSC.Element. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
special_agent_Queue |
Posted: Fri Dec 08, 2006 6:18 am Post subject: |
|
|
 Centurion
Joined: 27 Jul 2006 Posts: 102
|
Quote: |
Method 1:
1. Copied the input message to output tree.
2. Recursively traversed the message in output tree and used a similar statement as - SET Out_Cursor[NAME] = UPPER(In_Cursor). (Cursors are reference variables).
|
Why do you need to copy the input message to the output tree if you are just going to use SET Out_Cursor = UPPER(In_Cursor)?
Also, as stated in other posts above, check the type of what you are pointing to, and only convert if it is XMLNS.Element (not XMLNSC - that's only for v6), or only move if it is an Element.
Quote: |
Method 2:
1. Copied the input message to Environment tree.
2. Recursively traversed the message in output tree and used a similar statement as - SET Out_Cursor[NAME] = UPPER(In_Cursor). (Cursors are reference variables).
|
When you create a field in the Environment tree, use DOMAIN ('XMLNS') and it should be able to correctly copy the attributes. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Dec 08, 2006 6:22 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay, I missed that it was V5 - so using XMLNS is okay. Please don't use XML domain even in v5.
But you don't need to CHECK the Type of the element.
You just need to tell your MOVE statement to only MOVE to the next element of the type you're interested in.
This is done with the clause "TYPE". _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
ayanc |
Posted: Sun Dec 10, 2006 7:39 am Post subject: |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi All,
Thanx for your response.
Method 1:
Quote: |
However strange it may seem, the elements in the message in output queue remains in small case although traces taken before and after the output node shows the elements to be in upper case.
|
Any ideas on the above.
Method 2:
Quote: |
When you create a field in the Environment tree, use DOMAIN ('XMLNS') and it should be able to correctly copy the attributes.
|
Current code:
DECLARE REF_Cursor REFERENCE TO Input. ...[Some location]
SET Environment.Variables.ChangeCase.StartAt = REF_Cursor;
CALL Procedure to recursively traverse Environment.Variables.ChangeCase.StartAt and change to upper case.
Could you kindly tell me how to use the DOMAIN feature here? (Err - I mean the code. ;-D )
Thanx. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Dec 10, 2006 12:38 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Have you tried something like this?
Code: |
SET cursor NAME = UPPER(FIELDNAME(cursor)); |
And what was the result ??  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Mon Dec 11, 2006 5:25 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Could you kindly tell me how to use the DOMAIN feature here? |
You could search this forum and find it fairly quickly. The code is
Code: |
CREATE LASTCHILD OF Environment NAME 'XMLNS' DOMAIN 'XMLNS' |
Now, any syntax element which you copy to Environment.XMLNS will be owned by the XMLNS parser. The name of the node can be anything you want, but since you are copying from InputRoot.XMLNS, 'XMLNS' seems like as good a name as any. |
|
Back to top |
|
 |
ayanc |
Posted: Mon Dec 11, 2006 7:55 am Post subject: |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi fjp_saper,
That is precisely the code that I am using in the recursive function to transform data in both Method 1 and Method 2. It is the same reason why I cannot send a reference to the Input tree. I need to copy a specific data segment from the input tree to any modifiable tree, and then pass the reference to the function. In Method 1 I have copied the segment to Output tree and in Method 2 I have copied to Environment tree.
In Method 1: The output in queue remains in small case although traces show the data to have been converted into upper case.
Do any one of you have any idea as to why it is happening?
In Method 2: I am facing the problem with attributes becoming elements. However I am currently trying to work out with the solutions provided in this post.
Thanx. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 11, 2006 4:23 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
ayanc wrote: |
Hi fjp_saper,
That is precisely the code that I am using in the recursive function to transform data in both Method 1 and Method 2. It is the same reason why I cannot send a reference to the Input tree. I need to copy a specific data segment from the input tree to any modifiable tree, and then pass the reference to the function. In Method 1 I have copied the segment to Output tree and in Method 2 I have copied to Environment tree.
In Method 1: The output in queue remains in small case although traces show the data to have been converted into upper case.
Do any one of you have any idea as to why it is happening?
In Method 2: I am facing the problem with attributes becoming elements. However I am currently trying to work out with the solutions provided in this post.
Thanx. |
See the difference in your code and mine highlighted....
SET Out_Cursor[NAME] = UPPER(In_Cursor);
vs
SET Out_Cursor NAME = UPPER(FIELDNAME(In_Cursor));
You could as well use
DECLARE fname CHARACTER "";
SET fname = UPPER(FIELDNAME(In_Cursor));
SET Out_Cursor NAME = fname;
SET Out_Cursor = In_Cursor;
or
SET anchor.{fname} = In_Cursor;...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
ayanc |
Posted: Mon Dec 11, 2006 5:30 pm Post subject: |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi fjp_saper,
I do apologise for that.
Quote: |
SET Out_Cursor[NAME] = UPPER(In_Cursor);
|
The above code would affect the data in my tags. I have not used this code ... and I am sorry for misleading you.
I have used the following code:
Quote: |
SET Out_Cursor NAME = UPPER(FIELDNAME(In_Cursor));
|
However as I said ... when the message is written to the output queue ... it is written in SMALL case. I have seen the output using RFHUtil as well as double checked using amqsbcg to ensure that they are really in small case.
Traces taken before and after the output node show the tags to be in UPPER case. Debugger shows the tags to be in upper case after emerging from the compute node.
That is the reason I tried with Method 2.
Thanx. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Dec 12, 2006 3:08 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You did not specify clearly if you were in the MRM or XMLNS domain and if you have a message set with capital tags...and to make sure this is the message set referenced in the OutputRoot.Properties... _________________ MQ & Broker admin |
|
Back to top |
|
 |
ayanc |
Posted: Tue Dec 12, 2006 6:55 pm Post subject: |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi fjp_saper,
I am using XML domain, and there is no message set involved.
Please feel free to ask for any info you want.
Thanx. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Dec 13, 2006 4:18 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
ayanc,
There's something strange about this. The message tree is the only input to the XML serializer. I can assure you that the XML domain does not change the tag names when writing a message.
I suggest the following approach:
- Start a new message flow
- Start simple :MQInput -> Compute -> MQOutput.
- In the Compute node, just uppercase the tag names ( no copying to the Environment tree)
- If that works, start adding in the other function. |
|
Back to top |
|
 |
ayanc |
Posted: Tue Dec 19, 2006 8:27 pm Post subject: |
|
|
Voyager
Joined: 15 Nov 2004 Posts: 88
|
Hi All,
Sorry for the delay. Just back from a vacation. [ ]
Got the answer to the problem ... [ ]
Basically the code that works is :
SET RF_Cursor NAME = UPPER(FIELDNAME(RF_Cursor));
-- followed by
SET RF_Cursor = FIELDVALUE(RF_Cursor);
I had not used the above line, which is why I was facing the problem. However now it is coming as it is in the queue as well.
I guess this happened because as we are changing the name of the tags, we are creating a new set of tags (XML is case sensitive). But in the process we did not assign any new value to it. So, although it was showing as Upper case in the trace files, but during writing to the queue ... it was reverting back to the original values that had been copied in the output tree.
Anyway thanx a lot for all your help. It was a good learning experience.
Thanx. |
|
Back to top |
|
 |
|