简体   繁体   中英

XML Schema: Child element type based attribute value?

I am trying to make a schema where the type of an element is determined by the value of a parent's attribute. In particular, want I want to do is this

<argument name="foo" type="float">5.6</argument>

where the value of the argument should be enforced to conform with a floating point value. So that the type of the value element is of the type defined by the attribute of the argument element.

Now, I found an older post on the topic where it was stated that this cannot be done in XML-Schema 1.0.

So my question is; Is there a recommended alternate way to do it ? The closest I can think of is allowing something like

<argument name="foo">
    <float>5.6</float>
</argument>

Letting argument contain an element of the type type and then let float be derived from type .

Depends what you mean by "an alternate way". You can change your document design (eg to use xsi:type), you can use a different validation methodology (eg RelaxNG or Schematron), or you can move to XSD 1.1.

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