XSD data type based on attribute

Discussion in 'XML' started by Gopher-216, Apr 27, 2012.

  1. Gopher-216

    Gopher-216 Guest

    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?
    Gopher-216, Apr 27, 2012
    #1
    1. Advertising

  2. Gopher-216 wrote:
    > 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.


    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Apr 28, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,069
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    456
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Micah
    Replies:
    2
    Views:
    4,714
    Micah
    May 12, 2005
  4. Replies:
    8
    Views:
    9,008
    Martin Honnen
    Jun 9, 2005
  5. Replies:
    2
    Views:
    1,060
    Henry S. Thompson
    Mar 6, 2006
Loading...

Share This Page