Corona S.
Corona S.

Reputation: 47

Restricting mixed XML content via XSD?

I have a xml structure like this

<Main>1
  <Sub>2
    <Property>red</Property>
    <Function>0
      <Parameter>234</Parameter>
    </Function>
  </Sub>
</Main>

and I want to make a xsd for it. I know how to do this if there is no "1" behind "Main", no "2" behind "Sub" and no "0" behind "Function". But I really don't know how to do it if there is.

Can anyone help me to add a restriction to this xml? The numbers should not be greater than 1000.

Thanks a lot!

Upvotes: 1

Views: 39

Answers (1)

kjhughes
kjhughes

Reputation: 111491

It's a bad XML design. If you want to constrain those numbers, place them into an element or an attribute of their own.

As you have it, you can use a mixed content declaration, but you'll lose the ability to constrain the mixed text, which is what the numbers would be in that case.

You might be able to come up with an assertion (XSD 1.1 required, though) on the string value or text nodes of the parent element of the mixed content, but that'd be messy. Change the design if adding the numeric constraint is important to you.

Upvotes: 1

Related Questions