简体   繁体   中英

How to specify in a XML schema that 2 attributes can't be present at the same time?

Anyone knows how to prevent a XML to have 2 attributes at the same time?

I have an XML which gives information about liquid containers:

What I want

Example 1:

<container>
  <bottle volume=1/>
</container>

Example 2:

<container>
  <bottle size="small"/>
</container>

Example 3:

<container>
  <bottle/>
</container>

I use 2 different attributes to indicate the quantity of liquid a container can contain but I don't want to have the possibility to indicate twice the same information by putting both attributes at the same time:

What I don't want

<container>
  <bottle volume=1 size="small"/>
</container>

Anyone knows how to forbid that?

EDIT: I must use XSD 1.0

It can't be done in XSD 1.0.

It's easily done in XSD 1.1 using assertions (or type alternatives).

The traditional way to do this without XSD 1.1 is to use Schematron for a second validation pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM