• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Anything missing from the XSD?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I have requirement as in XML,

under <technicalData> any number of elements should come and under any number of element unit element only should come
Intially it was

<xs:element name="technicaldata" minOccurs="0" >
<xs:complexType>


<xs:element name="co2WLTC"  minOccurs="0" >
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="CharLimit30" maxOccurs="1" />
<xs:element name="unit" type="CharLimit8" maxOccurs="1" />
<xs:element name="preliminary" type="xs:boolean" maxOccurs="1" />
<xs:element name="code" type="CharLimit4" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType>

I have modified as

<xs:element name="technicaldata" minOccurs="0" >
<xs:complexType>

<xs:sequence>
<xs:any processContents="skip" maxOccurs="unbounded" minOccurs="0"/>

<xs:sequence>
<xs:element name="unit" type="CharLimit8" maxOccurs="1" />
</xs:sequence>


</xs:sequence>

</xs:complexType>

Please let me know if I am missing anything.

Thanks
Uj

 
Marshal
Posts: 6855
470
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you tested the code, what have you got as results?

Did the tests gave you confidence about implementation or otherwise?
 
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you said technicalData, but the schema said technicaldata. It is not a good start.
Then the summary of said "initial" schema is not really valid...

Giving all the benefit of the doubt, the schema you said you modified the initial one would not work as it will result in a non-determistic schema which is one of the constraint of w3c schema (1.0) design. The xs:any so written will take on a default namespace attribute which is "##any". Hence the schema engine will not be able to determine if the last element unit be intended to be one for xs:any or one actually intended to comply with schema's following xs:element ... hence, non-deterministic.

You can contemplate in alternating the conceptual design of it by
1) either you say the element unit come first before anything else validated by xs:any, ie, putting xs:element name="unit" before xs:any - but it is in a sense not a small design change;
2) or you can say my unit element belongs to a different namespace (using xs:element ref to refer to the element unit in another namespace of a schema other than the shown one) and add an attribute namespace="##targetNamespace" to the xs:any element;
2.1) or in the same spirit, you say unit belongs to the present targetNamespace but xs:any admits only anything other than the present targetNamespace, ie, adding an attribute namespace="##other" to the xs:any element - but 2) or 2.1) is quite a major design change.

With either of those, the non-deterministic issue is then resolved and you can proceed with the schema corrected accordingly.
 
ujwwala tembbe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,
I have tried with this
<xs:element name="technicaldata" minOccurs="0" >
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" maxOccurs="unbounded" minOccurs="0"/>

</xs:sequence>
</xs:complexType>
</xs:element>
It is working but I want only unit should be passed
<xs:element name="co2NefzGas"  minOccurs="0" >
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="CharLimit30" maxOccurs="1" />
<xs:element name="unit" type="CharLimit8" maxOccurs="1" />
<xs:element name="preliminary" type="xs:boolean" maxOccurs="1" />
<xs:element name="code" type="CharLimit4" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>


Can I give unit element as madatory under any elements

Thanks
Uj
 
g tsuji
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It is working but I want only unit should be passed
Can I give unit element as madatory under any elements


So I am led to understand that you only want to write xs:any under technicaldata but all the same you want whatever being admitted as pertinent to xs:any contains a unit element ("... under any elements" with "under" meant descendant of technicaldata, and "any" refers to xs:any.)

[1] First, you must understand in order to validate a "unit" element, the engine must perform validaion in order to validate it. Therefore, processContents="skip" cannot be.

So what to do? You must strengthen it to processContents="lax", strengthen to "strict" seems not what you want at all.

The validation according to lax entails that you must have the element unit "defined" as global element in the schema... So you first must isolate it and define it as global (in case you don't understand the concept, it means xs:element for "unit" must be the direct child of xs:schema element.

If your ChartLimit8 be complex type, change the above accordingly.

[2] Then you must understand that any other element such as co2NefzGas etc I suppose are defined only locally (other than globally) in the original schema. And then you want to spare any of them. That is fine. If by bad luck you have some globally defined xs:element with name that you want to pass to technicaldata as its descendant, then you have to make sure you have all those having unit as descendant having the cardinality minOccurs="1" that means mandatory exactly in narrative/normative term. (I am not sure you really understand but leave it as such for the moment.) Furthermore, those explicit globally defined element containing unit element must be written with a reference to the global element unit so defined. For instance this.

The only rigid thing I want to illustrate is the way to write the "unit" element (minOccurs="1" by default which means mandatory, if you want multiple unit, you add maxOccurs="unbounded" tp it, otherwise the default is maxOccurs="1".) All the rest y, z their types and cardinality are for illustration only. With that, the x will also be validated together with unit (mandatory) too.

I hope you understand... otherwise, I just have to say it is not that elementary as an excuse not able to convey to you the proper way of doing it in that approach.
 
g tsuji
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just want to add a remark: to use xs:any for the sole purpose announced cannot be done with side-effects which is not what wanted in the original design. The above solution is the closest one can do as a compromise... nothing forbid you to pass technicaldata to itself resulting in a recursion construction. But one has to live with it... (as xs:any is a tool with too much built-in power.)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!