Author |
Message
|
constantlearner |
Posted: Sat Jan 09, 2010 10:11 am Post subject: Generic Schema to be used in ESQL - Message Broker |
|
|
Newbie
Joined: 08 Jan 2010 Posts: 8
|
Hi,
I have a requirement in which i need to create a schema which looks very generic, for e.g. my xml looks like
Code: |
<Sales>
<Product>test</Product>
<Amount>245.80</Amount>
<ExtraCharges>
<Tax>5.6</Tax>
<Authority>ABC</Authority>
<Area>878</Area>
</ExtraCharges>
</Sales>
|
Now in the above xml, i know that every sales will have product, amount and extracharges. But within extracharges, every application can write some new tag, i.e. there is no defined tag within ExtraCharges. In the above example, we have tax, authority and area but my application can get something like <firstname>Antony</firstname> also in ExtraCharges.
ExtraCharges has thus to be defined as a tag in schema that can hold any other kind of tag. How should i define the schema in this case?
Thanks,
Antony[/code] |
|
Back to top |
|
 |
smdavies99 |
Posted: Sat Jan 09, 2010 10:57 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
If you know ALL the different tags that you will ever get then you can define them in a message model with the numoccurs=0.
Otherwise, you are going to have to rely on the self describing features of XML. This makes things somewhat more difficult and will most likely involve a lot more ESQL that you'd otherwise need.
Try a search on this forum for 'self describing xml' That may help. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
kimbert |
Posted: Sat Jan 09, 2010 1:29 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
First, if you are not already doing so, I recommend strongly that you use XMLNSC for this, and not MRM XML.
It may be worth your while to bookmark the XML Schema primer here:
http://www.w3.org/TR/xmlschema-0/
...and perhaps also the W3Schools schema tutorial here:
http://www.w3schools.com/Schema/default.asp
Quote: |
ExtraCharges has thus to be defined as a tag in schema that can hold any other kind of tag. |
You need to add an 'any' element as the only child of ExtraCharges.
http://www.w3.org/TR/xmlschema-0/#any
In the Message Broker Toolkit, you add an 'any' element as follows:
- Highlight ExtraCharges in the Outline view ( bottom left pane )
- Right-click and select 'Add wildcard element'.
You should then set the processContents and namespaces properties to get the required level of strictness ( you may not really want *any* tag to be included. Perhaps all of the allowed tags must come from a particular namespace? ). |
|
Back to top |
|
 |
constantlearner |
Posted: Sun Jan 17, 2010 6:32 pm Post subject: |
|
|
Newbie
Joined: 08 Jan 2010 Posts: 8
|
Kimbert, thanks for the links, it was really helpful.
I defined an element within my schema as below
Code: |
<xsd:element name="Payload" type="PayloadType"/>
|
The PayloadType I defined as below (so that it can take any kind of tags within it)
Code: |
<xsd:complexType name="PayloadType">
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
<xsd:anyAttribute/>
</xsd:complexType>
|
Now when I try defining my XML as below
Code: |
<Main>
<Payload>
<test>a</test>
</Payload>
</Main>
|
I'm getting the below error in XML Spy
Code: |
cvc-wildcard.2: While validating against complex type 'PayloadType', element <test> matched wildcard {##any} but no element declaration was found.
|
Two questions
1) Even though I defined the "any" tag and "any" attribute, I'm getting error while validating my input file against the schema
2) The Payload tag should be able to accept CDATA, XML and string types of messages. How should I define my Payload Element in Schema?
Thanks,
A-- |
|
Back to top |
|
 |
constantlearner |
Posted: Sun Jan 17, 2010 6:40 pm Post subject: |
|
|
Newbie
Joined: 08 Jan 2010 Posts: 8
|
Kimbert wrote:
Quote: |
- Right-click and select 'Add wildcard element'.
|
I have broker toolkit version 6.1.0.3 and I dont see this option in it.
Kimbert wrote:
Quote: |
You should then set the processContents and namespaces properties to get the required level of strictness ( you may not really want *any* tag to be included. Perhaps all of the allowed tags must come from a particular namespace? ).
|
The requirement says the tag can be anything, it need not come from a particular namespace. |
|
Back to top |
|
 |
goffinf |
Posted: Tue Jan 19, 2010 3:54 pm Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Since your xsd:any element declaration does not explicitly specify a value for the processContents attribute, it will default to 'strict'. In this mode the processor MUST validate elements that appear in the place of the wildcard.
I would suggest you set a processContents value of 'lax'.
Similarly if you want to allow elements to appear in place of the wildcard from any namespace you would specify a namespace attribute value of ##any.
Fraser. |
|
Back to top |
|
 |
|