How to define an attribute in XSD whose type can change dynamically

I need to define the "DataValue" attribute of the "MyData" element. But the requirement is that the type of "DataValue" can be dynamically changed, i.e. The data value can be a string in one instance, and in another case it can be int or bool. It can be any type of xml data. For example, in a single instance, xml might look like where the data value is xs: string

<MyData DataName = "Message" DataValue = "Hello" /> 

Otherwise, the data value may be xs: integer and xml will look like this:

 <MyData DataName = "Message" DataValue = "123" /> 

Please help me write the correct xsd for this.

  <xs:complexType name="MyData"> <xs:attribute name="DataName" type="xs:string" use="required" /> <xs:attribute name="DataValue" **type="????????"** use="required" /> </xs:complexType> 

If the attribute type can change dynamically, how can I indicate what is in XSD? Is there a way to indicate that the attribute type can be any of the xml data types and is not fixed? Please help me.

+4
source share
1 answer

You can use xsd: anyType for this.

+1
source

All Articles