How do I express this constraint with RELAX NG?

J

James McComb

Please, can someone tell me how I can express
this constraint using Relax NG?

I want these documents to be valid:

<memo>
<code>WithMessage</code>
<message>WithMessage means there is a message.</message>
</memo>

<memo>
<code>WithoutMessage</code>
<!-- WithoutMessage so no message -->
</memo>

And these documents to be invalid:

<memo>
<code>WithoutMessage</code>
<message>This element shouldn't exist.</message>
</memo>

<memo>
<code>WithMessage</code>
<!-- There should be a message here -->
</memo>

Thanks.

James McComb
 
B

Bob Foster

Like this:

<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="memo">
<choice>
<group>
<element name="code">
<value>WithMessage</value>
</element>
<element name="message">
<text/>
</element>
</group>
<element name="code">
<value>WithoutMessage</value>
</element>
</choice>
</element>
</start>
</grammar>

Bob Foster
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top