Possible with schema?

L

Lord0

Is it possible to validate/check for the following using a schema?

<question answer="yes">
<answer>This is the answer</answer>
</question>

OR

<question answer="no" />

Where "question" can change.....i.e.

The schema fragment which *would* validate this:

<question1 answer="yes">
<answer>This is the answer</answer>
</question1>

OR

<question1 answer="no" />

Would also be able to validate this:

<question2 answer="yes">
<answer>This is the answer</answer>
</question2>

OR

<question2 answer="no" />

WITHOUT hardcoding "question1", "question2" etc in the schema

Maybe Im going Friday afternoon mad!

Cheers

Lord0
 
L

Lord0

Redesign as <question number="2" ....>.

Hmm, I got as far as.......

<choice>
<element name="question" type="this:noAttributeType" />
<element name="question"
type="this:yesAttributeWithDescriptionType" />
</choice>

<complexType name="noAttributeType">
</complexType>

<complexType name="yesAttributeWithDescriptionType">
<sequence>
<element name="description" type="string" />
</sequence>
</complexType>

but of course I get "Unique Particle Attribution" violation.
 
U

usenet

Hmm, I got as far as.......

<choice>
<element name="question" type="this:noAttributeType" />
<element name="question"
type="this:yesAttributeWithDescriptionType" />
</choice>
...

I think what you're trying to do requires a co-constraint, and is not
currently possible with XML schema. I believe Relax-NG can do this.

You could aim for something like:

<question number="2"><yes answer="This is the answer"></...

or some variation on that theme.

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============================================
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top