Reputation: 4909
We're having some issues writing the correct (valid) xsd: - the xsd should validate on http://www.w3.org/2001/03/webdata/xsv - it should be possible to add the schema to an sql server schema collection (CREATE XML SCHEMA COLLECTION test AS '[xsd here]' - we need the 'title' attribute values to be specified in the xsd
This is (a drastically simplified) XML structure:
1) This was our first version (which obviously is not valid): You cannot have 2 elements with name 'input' which are different.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="test">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="input">
<xsd:complexType>
<xsd:attribute name="title" fixed="Pretty title" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="input">
<xsd:complexType>
<xsd:attribute name="title" fixed="Different title" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
2) second attempt:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="test" type="Test"/>
<xsd:complexType name="input1">
<xsd:attribute name="title" fixed="Pretty title" use="required"/>
</xsd:complexType>
<xsd:complexType name="input2">
<xsd:attribute name="title" fixed="Different title" use="required"/>
</xsd:complexType>
<xsd:complexType name="Test">
<xsd:sequence>
<xsd:element name="input" type="input1"/>
<xsd:element name="input" type="input2"/>
</xsd:sequence>
</xsd:complexType>
It would be great if someone can give us some insight on this.
Manu.
ps: In reality, our XML structures are way more complex then the example. We're building a web form generator. Here's another (still simple) example:
<?xml version="1.0" encoding="UTF-8"?>
<ZForm title="main title" attachment="attachment1" type="NM08">
<Part title="part title">
<SubTitle code="I.1)" title="title 1"/>
<ShortText title="short text title 1"/>
<SubTitle code="I.2)" title="title 2" subtitle="subtitle 1"/>
<SelectList type="select type" title="select title"/>
<ShortText title="short text title 2"/>
<MultiSelectList type="multiType2" title="multi select title"/>
<RadioButtonList type="yesNo" title="lala"/>
<SubTitle code="I.3)" title="some other title" subtitle="what?"/>
<MultiSelectList type="multiType2" title=""/>
</Part>
<Part title="second part title">
<Repeater add="add a new repeater item" remove="remove last repeating part">
<RepeatingPart>
<SubTitle code="II.1)" title="tiiiiiitle"/>
<ShortText/>
</RepeatingPart>
</Repeater>
</Part>
</ZForm>
Upvotes: 0
Views: 3405
Reputation: 163282
The XSD specification defines a constraint "Element Declarations Consistent" whose effect is that when two sibling elements have the same name, they must also have the same type.
XMLSpy is well known for not enforcing some of the more awkward rules in the spec. I don't know whether it's because they didn't get around to writing the code, or whether they felt that their version was an improvement, but it's always a good idea to check your schema using a tool whose approach to conformance is a bit more rigorous (Xerces is actually stronger on this than the W3C MSV service).
Upvotes: 2