Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XSD data type based on attribute

2 views
Skip to first unread message

Gopher-216

unread,
Apr 27, 2012, 6:02:50 PM4/27/12
to
Say I have an XML element
<data type="number">10</data>

Can an XML schema validate the contents of the data tag based on the value of an attribute?

Martin Honnen

unread,
Apr 28, 2012, 8:20:37 AM4/28/12
to
If you use the attribute the specification defines for that purpose
(xsi:type) and the data types defined in the specification (schema data
types) then yes e.g.

<data
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:type="xs:integer">10</data>

Of course with complete documents you would move the namespace
declarations up on the root element so you don't have to put them on
each element.


--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
0 new messages