Apologies if this is a silly question, I haven’t really done anything with xml up until now.
I want to be able to deserialise some xml into a class that has a property of type object. This property could be an int, guid or a string. In the xml I would like this property to be defined as an attribute. I would have expected my xsd to look something like this:
<xsd:complexType name="MyClass">
<xsd:attribute name="MyProperty" type="xsd:anySimpleType" />
</xsd:complexType>
However, visual studio intellisense doesn’t list the option, “xsd:anySimpleType”. Is this an issue with intellisense or am I doing something inherently wrong?
Although it’s legal to have an attribute of type xs:anySimpleType, I would avoid it and use xs:string instead. This is because the spec leaves many questions open about how such an attribute should behave. It’s not possible to restrict it using an enumeration or a regular expression, it’s very poorly defined what happens if you use it in an identity constraint, etc. The validation is exactly the same as for xs:string, but other aspects of the behaviour are fairly weird and likely to vary between implementations.
One could argue that xs:anySimpleType makes sense if you want later to define subtypes such as string, int, and URI. But that’s the only case I can think of in favour.