Author |
Message
|
Blobtastic |
Posted: Tue Aug 03, 2004 1:11 am Post subject: Problem with XML.attr |
|
|
Apprentice
Joined: 03 Nov 2003 Posts: 34 Location: uk
|
Hi,
I'm having a problem getting the output I'm expecting for an xml attribute.
My code is:-
IF InputBody.Amount <> ' ' THEN
SET "OutputRoot"."MRM"."Amt".(XML.attr)Ccy VALUE = "InputBody"."Currency";
SET WF_Item = InputRoot.XML.Amount;
SET WF_TotalLength = LENGTH(WF_Item);
SET WF_DecPoint = WF_TotalLength - 2;
SET WF_Item_PreDecimal = SUBSTRING(WF_Item FROM 1 FOR WF_DecPoint);
IF WF_Item_PreDecimal = ' ' THEN
SET WF_Item_PreDecimal = '0';
END IF;
SET WF_DecPoint = WF_DecPoint + 1;
SET WF_Item_PostDecimal = SUBSTRING(WF_Item FROM WF_DecPoint FOR 2);
SET "OutputRoot"."MRM"."Amt" = WF_Item_PreDecimal || ',' || WF_Item_PostDecimal;
END IF;
My output from this is:-
<Amt>2,227000<Ccy>USD</Ccy></Amt>
what I actually want is:-
<Amt Ccy = " USD "> 2,227000 </Amt>
In the MRM, I have a definde an element Amt with an associated attribute of Ccy.
Can anyone point me towards where the problem is? I'm not sure if I have a problem with the MRM definition, or a problem with the eSQL that I have defined.
I am using v2.1, CSD06. |
|
Back to top |
|
 |
wooda |
Posted: Tue Aug 03, 2004 1:24 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Hi Blobtastic,
1.) Check that you have set the the XML format property "Render" on Ccy to "XMLAttribute" in the message set. This will cause it to be written as an attribute.
2.) The (XML.attr) notaton in the ESQL field path is only valid for XML domain not MRM domain. The MRM use the messageset to determine which fields are to be written as Elements and Attributes.
Regards
Alex |
|
Back to top |
|
 |
Blobtastic |
Posted: Tue Aug 03, 2004 2:34 am Post subject: |
|
|
Apprentice
Joined: 03 Nov 2003 Posts: 34 Location: uk
|
Thanks for the reply Wooda.
1) The XML Format property 'Member Render' on Ccy is set to XMLAttribute.
2) I've been getting confused from trying various things out! I am currently doing this within the MRM domain (having previously tried xml, and got the sample output previously shown) but for some reason it will not allow me to set the attribute. If I drag the element I want over to the correct position, it appears to map correctly, but doesn't give me any output (I think this was why I originally switched to using xml domain).
My MRM code is:-
SET "OutputRoot"."MRM"."Amt"."Ccy" = "InputBody"."Currency";
SET "OutputRoot"."MRM"."Amt" = "InputBody"."Amount";
I can worry about the formatting later.
The output I get is:-
<xsd:Amt>10601</xsd:Amt>
Obviously this was with a different input file to the previous example. What I wanted was:-
<xsd:Amt Ccy "EUR">10601</xsd:Amt>
Any suggestions? If I trace the flow, it appears to totally ignore the currency line, as if you can't map to an attribute. |
|
Back to top |
|
 |
wooda |
Posted: Tue Aug 03, 2004 2:43 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Ok the problem here is that Amt is a complex element (it has attributes) with simple content (it also has a value).
With MRM (in v2.1) you need to set a "base type" for the complex type used by your Amt element.
So that the MRM knows what type the value for Amt will take.
Also try changing the ESQL to:
SET "OutputRoot"."MRM"."Amt"."Ccy" = "InputBody"."Currency";
SET "OutputRoot"."MRM"."Amt".*[1] = "InputBody"."Amount";
For XML domain you might find that the following works:
SET "OutputRoot"."XML"."Amt".(XML.Attr)"Ccy" = "InputBody"."Currency";
SET "OutputRoot"."XML"."Amt".*[1] = "InputBody"."Amount";
Regards,
- Alex |
|
Back to top |
|
 |
kimbert |
Posted: Wed Aug 04, 2004 1:01 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Hi Blobtastic,
Here's what you want as output: <xsd:Amt Ccy "EUR">10601</xsd:Amt>
Lets say that
- element Amt is of type xsd:int
- attribute Ccy is of type xsd:string
although in reality you will probably want to use your own simple types.
In v5 language, you need to do this:
1. Create a complex type 'AmtType'.
2. In the logical properties of 'AmtType' set 'Base Type Definition' to 'xsd:int'
3. Add an attribute 'Ccy' to complex type 'AmtType'. (You should notice at this point that you cannot add an element, because the complex type is based on a simple type).
You will probably want to create your own user-defined simple types for Amt and Ccy, but this is the pattern you should follow. |
|
Back to top |
|
 |
wooda |
Posted: Wed Aug 04, 2004 1:17 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Hi kimbert -
Please note Blobtastic said he's using V2.1 CSD06. So he can't do it the "V5 way".
What he/she is attempting should be possible in XML domain also. |
|
Back to top |
|
 |
Blobtastic |
Posted: Wed Aug 04, 2004 1:26 am Post subject: |
|
|
Apprentice
Joined: 03 Nov 2003 Posts: 34 Location: uk
|
Hi Alex and Kimbert,
Thanks for the interest. I got distracted by another problem yesterday, but will hopefully be able to return to this later today.
My problem is I am working from a very large Schema that I have imported, rather than from a mesasge set that I built myself, which is making it much harder for me to interpret. Later I will read up on 'base type' and look into both your suggestions.
Many thanks,
Blobtastic (bloke!) |
|
Back to top |
|
 |
Blobtastic |
Posted: Thu Aug 05, 2004 6:07 am Post subject: |
|
|
Apprentice
Joined: 03 Nov 2003 Posts: 34 Location: uk
|
Hello again,
Could you assist a bit more please!
I've attempted Alex's MRM code solution, and get the following result:-
<xsd:Amt xsi:nil="true" Ccy="10601"></xsd:Amt>
Despite the code you suggested, it seems to have put the amount in the currency attribute, and doesn't seem to recognise that the Amt tag should have a value. I'm now assuming that this is because the definition in the MRM is incorrect.
Under 'Types' in the message set, I have an entry called 'xsd_ActiveCurrrencyAndAmount', which is of Type compostion 'Simple Unordered Set'. This relates to the 'Amt' in my message. It is of Type Decimal. If I expand it, it has one line under it, 'Ccy', which is an XMLAttribute.
I am confused when you talk about 'base types'. Can you offer any more assisitance please? I suspect that there is something fundamentally wrong with the way that the schema importer has interpreted the 'Amt' field, but am a bit scared to make too many changes without fully understanding the problem.
Many thanks |
|
Back to top |
|
 |
wooda |
Posted: Thu Aug 05, 2004 7:23 am Post subject: |
|
|
 Master
Joined: 21 Nov 2003 Posts: 265 Location: UK
|
Sorry my mistake. Should have been the following.
MRM:
Code: |
SET "OutputRoot"."MRM"."Amt"."Ccy" = "InputBody"."Currency";
SET "OutputRoot"."MRM"."Amt".*[2] = "InputBody"."Amount"; |
XML:
Code: |
SET "OutputRoot"."XML"."Amt".(XML.Attr)"Ccy" = "InputBody"."Currency";
SET "OutputRoot"."XML"."Amt".*[2] = "InputBody"."Amount"; |
Of course the first child is Ccy so my original code was overwiting it with the amount
Not sure about the xsi:nil="true" attribute though. |
|
Back to top |
|
 |
Blobtastic |
Posted: Fri Aug 06, 2004 1:43 am Post subject: |
|
|
Apprentice
Joined: 03 Nov 2003 Posts: 34 Location: uk
|
Thanks Alex.
I tried your latest version, and got the following dramatic improvement:-
<xsd:Amt xsi:nil="true" Ccy="EUR"><Amount>10601</Amount></xsd:Amt>
So to get around this, I moved the value in amount into a variable first, and I now get :-
<xsd:Amt xsi:nil="true" Ccy="EUR">10601</xsd:Amt>
which is fairly close to what I require. I'm assuming I will be able to strip out the strange xsi.... line later.
I'm not quite sure why I need to move the value into a variable first, which I think is half my problem with the product - certain things seem to work, but I don't really know why!
Anyway, thank you very much for your time and help,
Blobtastic. |
|
Back to top |
|
 |
|