• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[XML Schema] same elementname, different attributes

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Michael Herrmann
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic