wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes [XML Schema] same elementname, different attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "[XML Schema] same elementname, different attributes" Watch "[XML Schema] same elementname, different attributes" New topic
Author

[XML Schema] same elementname, different attributes

Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
Hi,
I'm currently developing a tilebased game and I want to store informations about my game's tiles in an xml file. A tile's definition should look as similar as possible to this:

<tile id="anID">
<properties>
<property name="aUniquePropName1" type="string">test</property>
<property name="aUniquePropName2" type="boolean">true</property>
<property name="aUniquePropName3" type="int">32456</property>
</properties>
</tile>

The value of any <property> element should be validated depending on the type attribute's value. Additionally, I would like to use existing schema primitives such as int, string and boolean. My current approach for the definition of a tile's property looks like this:

<xs:complexType name="TilePropertyType" abstract="true">
<xs:simpleContent>
<xs:extension base="xs:anySimpleType">
<xs:attribute name="name" type="xs:Name" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

And a derivation of this type:

<xs:complexType name="String">
<xs:simpleContent>
<xs:restriction base="etg:TilePropertyType">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>

I'm using XMLSpy 2004 which validates the files before saving, and trying to save doesn't produce an error. However, if I try to switch to a graphical representation of my schema(there is a text view and several more graphical, a bit UML like views), I get the following error:
Unable to show schema:
The element xs:simpleType is unexpected at this location.
And the line "<xs:simpleType>" after "<xs:restriction base="etg:TilePropertyType">" in the complexType String is marked.

Is this a bug of XMLSpy(i suppose not) or is my schema really not valid and XMLSpy doesn't check everything when saving? If my schema is invalid, how could I correct it(with the same functionality) to make it valid?

What I'm doing is basically trying to have two supertypes: TilePropertyType and, in this example, xs:string. Is this possible in XML schemas?

Thanks for any answers,
Michael Herrmann
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Your second ComplexType definition seems to be wrong.
I don't understand what you are trying to acheive with
the second definition. Could you please elaborate, maybe
I am missing something here....


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
Thanks for your answer. It's hard to explain, so I'll post the full definition of "TileType". I guess this is the easiest way.



I'm using the abstract type TilePropertyType as a placeholder for TilePropertyType's subtypes String, Int, Boolean. I don't want to do the validation of e.g. int myself so I first extend TilePropertyType and then extend xs:int which does the validation for me(the validation works, actually).
[ September 30, 2004: Message edited by: Michael Herrmann ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Ok, to clarify what XMLSpy is doing, this is what I think -

When you save the file, it checks for 'well-formdness' since the
XSD is also an XML file. Once its well-formed, it allows save.
When you try to switch to a graphical/tree view, it is trying to
build your element definitions and runs into trouble because the
definition is not correct.

I am trying narrow what is wrong with the definition. I don't
have a lot of experience with Schemas, still learning.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [XML Schema] same elementname, different attributes
 
Similar Threads
unexpected child element xs:element error??
unble to validate xml against schema
Please Help me.- Schema problem
MS Exchange web service: If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute
Customizing JAXB