XSD: Require One Element with a specific Attribute value

A

Adam dR.

I would like to create an XSD that will verify the xml below has one
<config> element with the name attribute equal to 'DBC' all other
<config> elements are optional and their values don't matter. I
cannot restrict other <config> elements from being there. Is this
possible with XSD? If so could someone help me with an example?

<-- This should be VALID be cause it has one and only one config
element with name 'DBC' --/>
<project>
<config name='DBC' output='myprogram.exe'>
<file>myfile.dbr</file>
</config>
<config name='Make' output='myprog.exe'>
<file>myfile2.dbr</file>
</config>
</project>

<-- This should be VALID be cause it has one and only one config
element with name 'DBC' --/>
<project>
<config name='DBC' output='myprogram.exe'>
<file>myfile.dbr</file>
</config>
</project>

<-- This should be INVALID be cause it does not have a config element
with name 'DBC' --/>
<project>
<config name='comp.bat' output='myprogram.exe'>
<file>myfile.dbr</file>
</config>
<config name='Make' output='myprog.exe'>
<file>myfile2.dbr</file>
</config>
</project>
 

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

Latest Threads

Top