XSD data type based on attribute

G

Gopher-216

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?
 
M

Martin Honnen

Gopher-216 said:
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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top