[SCHEMA]Is there any way...?

N

Noiroi

Greetings -

Below you'll find a sample of my schema. What I'm trying to accomplish
is for any xml file created against this schema not to validate with
only element1.

<xsd:element name="PSD" type="RootDocumentType"/>
<xsd:complexType name="RootDocumentType">
<xsd:sequence>
<xsd:element name="element1"/>
<xsd:element name="element2" type="someTypes" minOccurs="0"/>
<xsd:element name="element3" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="element4" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- another attempt -->
<xsd:element name="PSD" type="someOtherType"/>
<xsd:group name="E234">
<xsd:sequence>
<xsd:element name="element2" type="someTypes" minOccurs="0"/>
<xsd:element name="element3" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="element4" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:group>
<xsd:complexType name="someOtherType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="element1"/>
<xsd:group ref="E234"/>
</xsd:sequence>
</xsd:complexType>

For example:
<!-- not valid -->
<PSD>
<element1/>
</PSD>

<!-- valid -->
<PSD>
<element1/>
<element2/>
<element3/>
<element4/>
</PSD>

<!-- valid -->
<PSD>
<element1/>
<element3/>
</PSD>

.... and so on. I don't know if it's possible, I'm hoping someone can
prove me wrong. I'm sure it's something simple I'm missing.
 
G

George Bina

Hi Noiroi,

You can write the content model as below, in order to force one of the
element2, element3 or element4 to appear after element1:
e1, (
(e2, e3*, e4*)|
(e3+, e4*) |
e4+
)

In XML Schema syntax that will be

<xsd:sequence>
<xsd:element name="element1"/>
<xsd:choice>
<xsd:sequence>
<xsd:element name="element2" type="someTypes"/>
<xsd:element name="element3" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="element4" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:sequence>
<xsd:element name="element3" type="someTypes"
maxOccurs="unbounded"/>
<xsd:element name="element4" type="someTypes" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:element name="element4" type="someTypes"
maxOccurs="unbounded"/>
<xsd:choice>
</xsd:sequence>

Best Regards,
George
 
N

Noiroi

Hi George -

Thank you for your input. I can see where you're going with your
example. I've tried it that way, but still e1 can validate on it's own.
Here are the allowed combinations:

e1, (
(e3*) |
(e2?) |
(e4*) |
(e2?, e3*) |
(e2?, e4*) |
(e3*, e4*) |
(e2?, e3*, e4*)
)

In your schema example, it was a choice of sequences. The problem that
I'm running in to is that the elements are optional within the
sequences. I can't figure out how to enforce a selection of optional
elements so that e1 is never alone. Any ideas?

Keeping the Faith-
Franklyn
 
N

Noiroi

Ok, I took another look at what you were describing and came up with:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xs:include schemaLocation="AttrTypes.xsd"/>
<xs:element name="PSD">
<xs:complexType>
<xs:sequence>
<xs:element ref="e1"/>
<xs:choice>
<xs:sequence>
<xs:element ref="e3" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e2" minOccurs="0"/>
<xs:element ref="e3" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="e4" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e3" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="e4" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e4" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e2" minOccurs="0"/>
<xs:element ref="e3" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e2" minOccurs="0"/>
<xs:element ref="e4" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="e2" minOccurs="0"/>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="e1" type="attrTypes"/>
<xs:element name="e3" type="attrTypes"/>
<xs:element name="e2" type="attrTypes"/>
<xs:element name="e4" type="attrTypes"/>
</xs:schema>

Which would work great, but I'm missing something simple here. I get an
error referring to the second e3 stating that it's not unique... I'm
not trying to redefine e3, just use it in another sequence. So, the
thought of using an abstract type comes to mind, but I'm thinking I'm
going to get the same results... any ideas?

-F
 
G

George Bina

Hi,

Look again into my example, it does not allow element1 alone. See that
all starting elements in each sequence must appear at least once.
The content model as you wrote it
e1, (
(e3*) |
(e2?) |
(e4*) |
(e2?, e3*) |
(e2?, e4*) |
(e3*, e4*) |
(e2?, e3*, e4*)
)

allows e1 alone. All the content that can be generated by the above
model plus the restriction that e1 should not be alone can be also
generated by the content model from my initial example.

Best Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top