Author |
Message
|
Erik Bakx |
Posted: Tue Jul 29, 2003 4:04 am Post subject: XML elements with more then one attribute |
|
|
Novice
Joined: 23 Apr 2002 Posts: 13
|
My XML input message has elements with more then one attribute, e.g.
<PartyID Tag='Beneficiary' Type='S'>
As far as I can see, it is only possible to define one attribute at the Member Properties of the XML layer of my messageset.
Should I give up using MRM or is there a solution?
Erik |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jul 29, 2003 6:01 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Good news. You can have as many attributes as you like within an element. If the element contains child elements as well as child attributes, you will need to follow these steps:
If the element only has attributes as its children,
1. Create a compound type for the element, and set its Type Composition to 'UnorderedSet'.
2. Create an element definition based on the compound type.
3. For each attribute, create an element within the compound type and change the 'Member Render' setting in its XML properties to 'XMLAttribute'
BUT if the element has elements as well as attributes as its children,
1. Create a compound type for the element, and set its Type Composition to 'Sequence'
2. Create the element based on the compound type.
3. Create two embedded compound types within the first compound type - one for the attributes and one for the elements.
4. Change the first embedded compound type to 'Unordered Set' - this one is for the attributes, which are allowed to arrive in any order they like.
The second embedded compound type will default to 'OrderedSet' which is what you want for the elements (presumably).
5. For each attribute, create an element within the first embedded compound type and change the 'Member Render' setting in its XML properties to 'XMLAttribute'
6. For each child element, create an element within the second compound type. |
|
Back to top |
|
 |
Erik Bakx |
Posted: Tue Jul 29, 2003 9:19 am Post subject: |
|
|
Novice
Joined: 23 Apr 2002 Posts: 13
|
Thanks, but I am affraid this wil not solve my problem since the element with two attributes also has a value or do I misunderstand the solution?
e.g.
<PartyID Tag="Beneficiary" Type="S">abc</PartyID>
<PartyID Tag="Originator" Type="S">xyz</PartyID>
By the way, does anyone know in ESQL how I address the values 'abc' and 'xyz'?
Erik |
|
Back to top |
|
 |
scaryjase |
Posted: Tue Jul 29, 2003 9:34 am Post subject: |
|
|
Novice
Joined: 17 Jul 2003 Posts: 22
|
not entirely sure how you would do it as a message set, but the following ESQL will create your message and hence you could use similar ESQL to read said message...
SET OutputRoot.XML.PartyID = 'abc';
SET OutputRoot.XML.PartyID.(XML.Attribute)Tag = 'Beneficiary';
SET OutputRoot.XML.PartyID.(XML.Attribute)Type = 'S'; _________________ scary |
|
Back to top |
|
 |
kimbert |
Posted: Wed Jul 30, 2003 12:31 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
You're still OK - don't give up on the MRM just yet! This scenario is explicitly catered for in the MRM data model.
Your element looks something like this
<element1 attr1="attrvalue1" attr2="attrvalue2">elValue1</element1>
You should model the attributes exactly as I described in my previous post, but you should also set the 'Base Type' field on the element's compound type. If the value of the element is a string, set it to STRING. Otherwise, you can set it to INTEGER, DECIMAL, FLOAT etc. |
|
Back to top |
|
 |
Erik Bakx |
Posted: Fri Aug 01, 2003 1:31 am Post subject: |
|
|
Novice
Joined: 23 Apr 2002 Posts: 13
|
You are right, it does work - I was forgotten a compound type can have a value as well.
I still miss the advantages of using MRM: mapping an element and attribute(s) to a specific element in my message tree in stead of testing wich attribute value is present, but I guess I have to live with that.
Erik |
|
Back to top |
|
 |
kimbert |
Posted: Fri Aug 01, 2003 2:21 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Glad that worked. I was a bit puzzled by your remark about accessing the values. You should be able to access the element's value ( "elValue1" in my example) in the normal way.
e.g. "InputBody.Element1" should return 'elValue1' in my example
The values of the attributes should also be accessible
e.g. "InputBody.Element1.attr1' should return 'attrvalue1' in my example
So...what is it that you are still missing  |
|
Back to top |
|
 |
Erik Bakx |
Posted: Fri Aug 01, 2003 3:23 am Post subject: |
|
|
Novice
Joined: 23 Apr 2002 Posts: 13
|
My input contains one or more of the following lines:
<PartyID Tag="Beneficiary" Type="S">abcd</PartyID>
<PartyID Tag="Sender" Type="S">efgh</PartyID>
<PartyID Tag="Originator" Type="S">ijkl</PartyID>
<PartyID Tag="Ordering" Type="S">mnop</PartyID>
<PartyID Tag="Debit" Type="S">qrst</PartyID>
<PartyID Tag="Instructing" Type="S">uvwx</PartyID>
These will map to the following (partial) message tree:
PartyID = 'abcd'
(
Tag = 'Beneficiary'
Type = 'S'
)
PartyID = 'efgh'
(
Tag = 'Sender'
Type = 'S'
)
PartyID = 'ijkl'
(
Tag = 'Originator'
Type = 'S'
)
PartyID = 'mnop'
(
Tag = 'Ordering'
Type = 'S'
)
PartyID = 'qrst'
(
Tag = 'Debit'
Type = 'S'
)
PartyID = 'uvwx'
(
Tag = 'Instructing'
Type = 'S'
)
When it would have been possible to enter more than one attribute and value in the MRM my input would have mapped to the following tree:
BeneficiaryPartyID = 'abcd'
SenderPartyID = 'efgh'
OriginatorPartyID = 'ijkl'
OrderingPartyID = 'mnop'
DebitPartyID = 'qrst'
InstructingPartyID = 'uvwx'
No doubt you will agree with me the latter is much easier to process.
Now I have to check every instance of PartyID wich value its attribute Tag has.
Erik |
|
Back to top |
|
 |
kimbert |
Posted: Fri Aug 01, 2003 4:08 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I certainly agree that the second way is easier. Fortunately, the MRM can do what you want. Sorry I did not point this out earlier - I thought you wanted multiple attributes, whereas what you really want is to identify an element using one of its attributes.
The solution is to set the 'Member Render' property for the element to 'XMLElementAttrId'. This instructs the MRM XML parser to look for a named attribute which identifies the element. You will have to specify the name by setting the property 'Member ID Attribute Name' on the element 'PartyID' to 'Tag'.
I'd like to know how you get on...let me know if it works for you., |
|
Back to top |
|
 |
Erik Bakx |
Posted: Fri Aug 01, 2003 4:45 am Post subject: |
|
|
Novice
Joined: 23 Apr 2002 Posts: 13
|
So now we're back to my first question.
It is only possible to specify one attribute at the Member properties and I have two, or would it be sufficient to specify (the identifying) one of them?
Erik |
|
Back to top |
|
 |
kimbert |
Posted: Fri Aug 01, 2003 5:13 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
The Member properties of the parent element only allows a single attribute to be specified, because that attribute will be used to identify the element.
However, there's nothing to stop you modelling other attributes which are just carrying data, using the facilities which I described in my earlier posting.
In your case, you should consume the identifying attribute by using the XMLElementAttrID setting on the element. If you're interested in the value of the other attribute, you should model that as an element with its 'Member Render' property set to 'XMLAttribute'. |
|
Back to top |
|
 |
|