What is wrong with this .XSD?

Discussion in 'XML' started by Casper B, Mar 2, 2005.

  1. Casper B

    Casper B Guest

    I have trouble constructing an .xsd to validate the following simple XML:

    ------
    <?xml version = "1.0" encoding="UTF-8"?>
    <FormatSpec FormatName="Test" Encoding="ISO-8859-1" TableName="RecordSet"
    xmlns="http://www.xyz.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="FormatSpec.xsd">

    <RowSpec Iterations="1">
    <ColSpec BeginOffset="0" EndOffset="8" RegExMatch="udgstart"/>
    </RowSpec>

    <RowSpec RowName="Record">
    <ColSpec BeginOffset="0" EndOffset="12" ColName="BuildingId"/>
    <ColSpec BeginOffset="17" EndOffset="21" ColName="StartDateYear"/>
    <ColSpec BeginOffset="55" EndOffset="80" Trim="true" ColName="Name"/>
    </RowSpec>
    </FormatSpec>
    ------

    My parser (oracle v2 for Java) only seems to validate the top element
    and never any attributtes even though I (think) I specify this with the
    following .xsd schema:

    ------
    <?xml version="1.0" encoding="windows-1252" ?>

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.xyz.com"
    targetNamespace="http://www.xyz.com"
    elementFormDefault="qualified"
    attributeFormDefault="qualified">

    <!-- Entry point? -->
    <xs:element name="FormatSpec" type="FormatSpecType"/>

    <xs:complexType name="FormatSpecType">

    <xs:sequence maxOccurs="unbounded" minOccurs="0">
    <xs:element name="RowSpec" type="RowSpecType"/>
    </xs:sequence>

    <xs:attribute name="FormatName" type="xs:normalizedString"/>
    <xs:attribute name="Encoding" type="xs:normalizedString"
    default="ISO-8859-1"/>
    <xs:attribute name="TableName" type="xs:normalizedString"
    default="RecordSet"/>

    </xs:complexType>

    <xs:complexType name="RowSpecType">

    <xs:sequence maxOccurs="unbounded" minOccurs="0">
    <xs:element name="ColSpec" type="ColSpecType"/>
    </xs:sequence>

    <xs:attribute name="Iterations" default="9999999"
    type="xs:positiveInteger"/>
    <xs:attribute name="RowName" type="xs:normalizedString"
    default="Record"/>

    </xs:complexType>

    <xs:complexType name="ColSpecType">
    <xs:attribute name="BeginOffset" type="xs:nonNegativeInteger"
    default="0"/>
    <xs:attribute name="EndOffset" type="xs:positiveInteger"/>
    <xs:attribute name="Trim" default="false"
    type="xs:boolean"/>
    <xs:attribute name="RegExMatch" type="xs:string"/>
    <xs:attribute name="ColName" type="xs:normalizedString"/>
    </xs:complexType>

    </xs:schema>
    ------

    What am I doing wrong? Is it impossible to validate attributtes (all
    examples I see deal with validating element content).

    Regards,
    Casper
     
    Casper B, Mar 2, 2005
    #1
    1. Advertising

  2. Casper B wrote:

    > I have trouble constructing an .xsd to validate the following simple XML:
    >
    > ------
    > <?xml version = "1.0" encoding="UTF-8"?>
    > <FormatSpec FormatName="Test" Encoding="ISO-8859-1" TableName="RecordSet"
    > xmlns="http://www.xyz.com"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocation="FormatSpec.xsd">


    schemaLocation takes at list of white space separated namespaceURIs and
    schema URIs e.g.
    xsi:schemaLocation="http://www.xyz.com FormatSpec.xsd"

    > <RowSpec Iterations="1">
    > <ColSpec BeginOffset="0" EndOffset="8" RegExMatch="udgstart"/>
    > </RowSpec>
    >
    > <RowSpec RowName="Record">
    > <ColSpec BeginOffset="0" EndOffset="12" ColName="BuildingId"/>
    > <ColSpec BeginOffset="17" EndOffset="21" ColName="StartDateYear"/>
    > <ColSpec BeginOffset="55" EndOffset="80" Trim="true" ColName="Name"/>
    > </RowSpec>
    > </FormatSpec>
    > ------
    >
    > My parser (oracle v2 for Java) only seems to validate the top element
    > and never any attributtes even though I (think) I specify this with the
    > following .xsd schema:
    >
    > ------
    > <?xml version="1.0" encoding="windows-1252" ?>
    >
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > xmlns="http://www.xyz.com"
    > targetNamespace="http://www.xyz.com"
    > elementFormDefault="qualified"
    > attributeFormDefault="qualified">


    Your attributes above are all unqualified (in no namespace) so here you
    should use
    attributeFormDefault="unqualified"


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 2, 2005
    #2
    1. Advertising

  3. Hi,

    The xsi:schemaLocation attribute needs to have pairs of values: the
    namespace, followed by whitespace, then the schema location.

    So, it should look like this:

    xsi:schemaLocation="http://www.xyz.com FormatSpec.xsd"

    Maybe it's not even finding the schema because of this. The schema
    looks all right at first glance.

    Hope that helps,
    Priscilla
    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Priscilla Walmsley, Mar 2, 2005
    #3
  4. Casper B

    Casper B Guest

    Thank you both for the feedback, :)

    When I correct the schemaLocation indeed things start to clear up,
    however it would appear my parser (Oracle DOM v2) is unable to load the
    schema:

    ---
    <Line 7, Column 59>: XML-24500: (Error) Can not build schema
    'http://www.qqsoft.dk' located at 'FormatSpec.xsd'
    com.xyz.dex.xml.flat2xml.ParseException: I/O error: no protocol:
    ---

    However, if I write the full location of the schema
    (http://www.qqsoft.dk/FormatSpec.xsd" instead of just "FormatSpec.xsd")
    parsing with validation functions just as I wanted it.

    I realize this is probably an internal parser issue, but I was just
    wondering if you have suggestion as to why this is?

    Thanks again,
    Casper
     
    Casper B, Mar 2, 2005
    #4
  5. Casper B wrote:


    > When I correct the schemaLocation indeed things start to clear up,
    > however it would appear my parser (Oracle DOM v2) is unable to load the
    > schema:
    >
    > ---
    > <Line 7, Column 59>: XML-24500: (Error) Can not build schema
    > 'http://www.qqsoft.dk' located at 'FormatSpec.xsd'
    > com.xyz.dex.xml.flat2xml.ParseException: I/O error: no protocol:
    > ---
    >
    > However, if I write the full location of the schema
    > (http://www.qqsoft.dk/FormatSpec.xsd" instead of just "FormatSpec.xsd")
    > parsing with validation functions just as I wanted it.
    >
    > I realize this is probably an internal parser issue, but I was just
    > wondering if you have suggestion as to why this is?


    FormatSpec.xsd is a relative URL perhaps your parser is expecting an
    absolute URL and trying to treat FormatSpec.xsd as an absolute URL then
    fails with the message "no protocol" as the protocol part of a URL (e.g.
    http: or file: or ftp:) is missing.
    But as said, questions about a particular parser are often better
    answered on mailing lists or forums dedicated to the parser.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 2, 2005
    #5
    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,143
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    506
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    878
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    803
    Peter Aberline
    Apr 5, 2004
  5. Bernd Oninger
    Replies:
    1
    Views:
    534
    Henry S. Thompson
    Jun 30, 2004
Loading...

Share This Page