My Schema allows a specific element to be optional, but when I encounter a different also optional element later on in the file, I need the previous one to be present. How can I ensure this via XSD?
Example:
<settings>
<file name="narf.txt"/>
<metafile name="narf.meta"/>
<filtermeta>true</filtermeta>
</settings>
should be valid,
<settings>
<file name="narf.txt"/>
<metafile name="narf.meta"/>
</settings>
and
<settings>
<file name="narf.txt"/>
</settings>
should be valid too,
<settings>
<file name="narf.txt"/>
<filtermeta>true</filtermeta>
</settings>
should not be valid.
Try the following schema definition:
I’ve run your first three examples against this schema using xmllint and they validate correctly. The fourth example fails with:
as expected.