Author |
Message
|
javaforvivek |
Posted: Mon Mar 28, 2005 11:25 pm Post subject: Validating XML against external xml schema |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi,
I have an XML message which I want to validate against an external schema (and not the MSgDef) in my msg flow. How can I do it?
I have XML files generated from a Microsoft Schema. For e.g.,
Schema is:
Quote: |
<?xml version="1.0"?>
<!-- This XML-document contains the Transaction layout of a Partner SettlementB2C - transaction. -->
<!-- Version: 1.1 Date: 2002-04-12 -->
<!-- Input for the XML-schema's: document R021E:Transaction Layouts. -->
<!-- This schema definition is according the Microsoft schema definition, in specific MSXML 3.0 -->
<!-- Website: http://msdn.microsoft.com/downloads/default.asp?url=/code/sample.asp?url=/msdn-files/027/000/537/msdncompositedoc.xml-->
<!-- The used XML-datatypes are also according those used by Microsoft. -->
<!-- Website: http:\\msdn.microsoft.com\xml\reference\schema\datatypes.asp -->
<Schema name="Partner_Settlement_Schema"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<!-- ElementTypes for Partner Settlement. -->
<ElementType name="SettlementEndDate" content="textOnly" dt:type="date"/>
<ElementType name="SettlementEndTime" content="textOnly" dt:type="time"/>
<ElementType name="SettlementStartDate" content="textOnly" dt:type="date"/>
<ElementType name="SettlementStartTime" content="textOnly" dt:type="time"/>
<ElementType name="Date" content="textOnly" dt:type="date"/>
<ElementType name="ExternalReferenceCode" content="textOnly" dt:type="string"/>
<ElementType name="Partner" content="textOnly" dt:type="i4"/>
<ElementType name="Time" content="textOnly" dt:type="time"/>
<ElementType name="TotalNumber" content="textOnly" dt:type="i4"/>
<ElementType name="TotalAmount" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalGrossContributionCustomer" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalGrossContributionCost" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalGrossContributionMargin" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalGrossContributionPartner" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalReturnedGrossContributionCosts" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalReturnedGrossContributionMargin" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TotalVATAmount" content="textOnly" dt:type="fixed.14.4"/>
<ElementType name="TypeID" content="textOnly" dt:type="i4"/>
<ElementType name="SalesUnit" content="textOnly" dt:type="i4"/>
<!-- Partner Settlement:Transaction. -->
<ElementType name="PartnerSettlementTransaction" content="eltOnly" model="closed" order="seq">
<element type="SettlementEndDate" minOccurs="1" maxOccurs="1"/>
<element type="SettlementEndTime" minOccurs="1" maxOccurs="1"/>
<element type="SettlementStartDate" minOccurs="1" maxOccurs="1"/>
<element type="SettlementStartTime" minOccurs="1" maxOccurs="1"/>
<element type="Date" minOccurs="1" maxOccurs="1"/>
<element type="ExternalReferenceCode" minOccurs="1" maxOccurs="1"/>
<element type="Partner" minOccurs="1" maxOccurs="1"/>
<element type="Time" minOccurs="1" maxOccurs="1"/>
<element type="TotalNumber" minOccurs="1" maxOccurs="1"/>
<element type="TotalAmount" minOccurs="1" maxOccurs="1"/>
<element type="TotalGrossContributionCustomer" minOccurs="1" maxOccurs="1"/>
<element type="TotalGrossContributionCost" minOccurs="1" maxOccurs="1"/>
<element type="TotalGrossContributionMargin" minOccurs="1" maxOccurs="1"/>
<element type="TotalGrossContributionPartner" minOccurs="1" maxOccurs="1"/>
<element type="TotalReturnedGrossContributionCosts" minOccurs="0" maxOccurs="1"/>
<element type="TotalReturnedGrossContributionMargin" minOccurs="0" maxOccurs="1"/>
<element type="TotalVATAmount" minOccurs="1" maxOccurs="1"/>
<element type="TypeID" minOccurs="1" maxOccurs="1"/>
<element type="SalesUnit" minOccurs="1" maxOccurs="1"/>
</ElementType>
</Schema>
|
And xml message is:
Quote: |
<?xml version="1.0" encoding="UTF-8"?>
<PartnerSettlementTransaction xmlns="x-schema:d:\schema\Partner-Settlement-schema1_0.xml">
<SettlementEndDate>2004-10-18</SettlementEndDate>
<SettlementEndTime>06:59:59</SettlementEndTime>
<SettlementStartDate>2004-10-17</SettlementStartDate>
<SettlementStartTime>07:00:00</SettlementStartTime>
<Date>2004-10-17</Date>
<ExternalReferenceCode>1065722</ExternalReferenceCode>
<Partner>1</Partner>
<Time>03:10:05</Time>
<TotalNumber>11</TotalNumber>
<TotalAmount>3055.6700</TotalAmount>
<TotalGrossContributionCustomer/>
<TotalGrossContributionCost>92.6000</TotalGrossContributionCost>
<TotalGrossContributionMargin>36.0000</TotalGrossContributionMargin>
<TotalGrossContributionPartner>128.3100</TotalGrossContributionPartner>
<TotalVATAmount/>
<TypeID>260</TypeID>
<SalesUnit>27</SalesUnit>
</PartnerSettlementTransaction> |
_________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
JLRowe |
Posted: Tue Mar 29, 2005 7:53 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
You will have to serialise the message and validate it using a java node. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Mar 30, 2005 12:19 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I want to validate against an external schema (and not the MSgDef) |
Why not create a message set from the schema, and switch on validation in the message flow? ( I know you've already thought of that approach - I'm just interested in why you decided not to use it ) |
|
Back to top |
|
 |
javaforvivek |
Posted: Wed Mar 30, 2005 4:56 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
This is just because the schema that I have is Microsoft schema.
I have tried to create msgset from it but it gave lots of errors.
I have given this schema in the earlier post, if you are interested, you can use both the schema as well as the sample msg and try to validate it. _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
martinrydman |
Posted: Wed Mar 30, 2005 7:23 am Post subject: |
|
|
 Centurion
Joined: 30 Jan 2004 Posts: 139 Location: Gothenburg, Sweden
|
I'm sure this has been discussed in this forum earlier, but my understanding, (limited) experience and feedback from colleagues would suggest that the whole concept of validating XML againts schemas is flawed for the reasons given by Vivek, i.e. a schema must be imported to the MRM, and there is no one-to-one correspondence between the XML-schema rules and the MRM-rules. This will often mean that after importing a schema, you must tweak it to comply with the MRM. Any tweaking mean that:
1. The possibility exists that the MRM model will in fact not correspond to the schema logically
2. A change in the schema will call for a re-import and subsequent tweaking of the MRM, a sure recepie for introducing errors
I have collegues who have resorted to writing their own java plug-ins for this purpose, with limited success.
Is it only me, or is this whole area immature in the product?
/Martin |
|
Back to top |
|
 |
JLRowe |
Posted: Wed Mar 30, 2005 2:02 pm Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
There are 2 problems with MRM:
1) It does not fully support XML schema, certain constructs are rejected on import, and MRM tries to emulate some constructs but fails miserably.
2) MRM does not fully validate against the message model (i.e. a message that does not conform to the schema may be accepted by MRM)
Remember, with MRM the tooling stores a message set as a schema, but when you deploy this is translated to the message broker internal format - which has a significantly different model to XML schema - hence the mismatch.
Unfortunately then, the only way that you can be absolutely certain that a message conforms to a schema is to serialize the message and validate it in a java node. Slow and messy. |
|
Back to top |
|
 |
javaforvivek |
Posted: Wed Mar 30, 2005 8:26 pm Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
This is what i got from help on MQInput Node:
Quote: |
Select Validation in the properties dialog navigator if you want the MRM parser to validate the body of messages against the dictionary generated from the message set. (If a message is propagated to the failure terminal of the node, it is not validated.)
|
Also, Only for MRM domain we need to set properties like MsgSet, MsgFormat and MsgType and NOT for any other domain.
It clearly shows that if you want to use any other domain than MRM, then Broker will not validate (check well-formedness and validity) of the input XML message.
If it is so, then we definitely need some other mechanism to achieve validation tasks.
Any comments on this? _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
JLRowe |
Posted: Thu Mar 31, 2005 3:31 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
Yep only MRM validates the content. Of course, the XML and XMLNS parsers will make sure the XML is well formed, but cannot validate content.
As said, if you want to thoroughly validate against a schema then Java is the only way to go. You could write a custom node and include the URL of the schema as a property, you could then deploy the schema in a BAR file. Again, messy but a bit more manageable. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Mar 31, 2005 10:46 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
The above comments are mostly accurate. Bear in mind, though, that unless you want exact XML Schema validation, the MRM does a good job. The differences between MRM validation and XML Schema validation are actually quite small, and most non-conforming documents will be rejected by the MRM validator. |
|
Back to top |
|
 |
martinrydman |
Posted: Thu Mar 31, 2005 11:26 am Post subject: |
|
|
 Centurion
Joined: 30 Jan 2004 Posts: 139 Location: Gothenburg, Sweden
|
The thing that itches the most is the tweaking bit. If I could import a schema and the MRM would swollow it, it'd be less of a hassle.
Next philosophical question here is: how often do we really want/need the broker to do the validation? When asked by customers, I usually answer, As seldom as possible, i.e. you should have really good reasons to introduce validation in the broker.
But that's another story
/Martin |
|
Back to top |
|
 |
kimbert |
Posted: Thu Mar 31, 2005 12:53 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Fair point. Maybe v6 will remove the need for the tweaking... |
|
Back to top |
|
 |
JLRowe |
Posted: Thu Mar 31, 2005 2:57 pm Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
Kimbert I disagree, I had a series of corporate schema's to import that needed refactoring so they would import into MRM.
False negatives can also be a problem with complex schema's. For example, a choice containing a group would always fail validation for a valid instance document.
The other problem is false positives, where an invalid (but well formed document) passes validation, a minoccurs or maxoccurs >1 is an example of this (even though the tooling warns you). This is problematic in that it is impossible to test for, and the business logic is not coded to cope with invalid documents - ensuring all sorts of chaos. |
|
Back to top |
|
 |
sri |
Posted: Tue Apr 05, 2005 10:22 am Post subject: |
|
|
 Apprentice
Joined: 14 Mar 2004 Posts: 32 Location: Chennai - India
|
Hi
I have similar problem in using message flow for validating XML messages.
my requirement is to validate the XML message using imported schema (as MRM) in compute node. I used ESQL to validate the XML message by parsing them. The statement is as follows
CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(InMsgBlob SET MsgSetChr OPTIONS ValidateValue + ValidateContent + ValidateException);
The problem I face is
1. The actual validation of MRM is taking place only at the MQOutput Node or Trace node (with ${Root} in it). ie The Root evaluvation happens only at the Trace/MQOutput Node.
Is there any way by which I can validate the XML message within a compute node without using Trace/MQOutput node.
thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Apr 05, 2005 10:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Did you try setting the Validation property on the compute node? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sri |
Posted: Wed Apr 06, 2005 12:06 am Post subject: |
|
|
 Apprentice
Joined: 14 Mar 2004 Posts: 32 Location: Chennai - India
|
hi
Yes, I tried configuring the compute node's validation option. still looks like the actual validation is happening only at the MQOutput Node / any of the Trace node with (${Root}) in it. |
|
Back to top |
|
 |
|