General view xsd

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="package" type="typeA"/> <!-- тип typeA --> <xs:complexType name="typeA"> <xs:sequence> <xs:element name="tag"> <xs:complexType> <xs:complexContent> <xs:restriction base="typeB"> <xs:choice> <xs:element name="tag" type="xs:string"/> </xs:choice> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <!-- тип typeB --> <xs:complexType name="typeB"> <xs:choice> <xs:element name="tag" type="xs:string"/> <xs:element name="tag" type="xs:time"/> </xs:choice> </xs:complexType> </xs:schema> 

Scheme

There are nodes with the same name, but with a different type of value. In this case, the time and string values. How can you describe them? In the complexType, with this entry, an error occurs, saying that the two names are the same.

  • In the proposed form and predefined types can not. You can, if you declare a custom abstract type of the tag element and then describe the types that specify it. Almost like in the PLO, only in a declarative style. You cannot specify two types of stored values ​​for one variable in <select language>, you can only not specify the type at all (if the language supports such constructions) or specify some general type whose heirs are valid values, as well here. - rdorn
  • In languages ​​with dynamic typing, it is not difficult to hang several types on one variable. In this case, the ambush arises because of the situation that xml is already hard-coded in several ways. And I tried to use xsd to describe it, which in the forehead fails. But in xsd 1.1 you can do it, albeit terribly cunning: through <xs: alternative> and <xs: key>. Also, we have been looking for an open source 1.1 parser for a very long time - user5555232

0