What is wrong with this .XSD?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Casper B

    What is wrong with this .XSD?

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

    ------
    <?xml version = "1.0" encoding="UTF-8"?>
    <FormatSpec FormatName="Tes t" Encoding="ISO-8859-1" TableName="Reco rdSet"
    xmlns="http://www.xyz.com"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocat ion="FormatSpec .xsd">

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

    <RowSpec RowName="Record ">
    <ColSpec BeginOffset="0" EndOffset="12" ColName="Buildi ngId"/>
    <ColSpec BeginOffset="17 " EndOffset="21" ColName="StartD ateYear"/>
    <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="windo ws-1252" ?>

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.xyz.com"
    targetNamespace ="http://www.xyz.com"
    elementFormDefa ult="qualified"
    attributeFormDe fault="qualifie d">

    <!-- Entry point? -->
    <xs:element name="FormatSpe c" type="FormatSpe cType"/>

    <xs:complexTy pe name="FormatSpe cType">

    <xs:sequence maxOccurs="unbo unded" minOccurs="0">
    <xs:element name="RowSpec" type="RowSpecTy pe"/>
    </xs:sequence>

    <xs:attribute name="FormatNam e" type="xs:normal izedString"/>
    <xs:attribute name="Encoding" type="xs:normal izedString"
    default="ISO-8859-1"/>
    <xs:attribute name="TableName " type="xs:normal izedString"
    default="Record Set"/>

    </xs:complexType>

    <xs:complexTy pe name="RowSpecTy pe">

    <xs:sequence maxOccurs="unbo unded" minOccurs="0">
    <xs:element name="ColSpec" type="ColSpecTy pe"/>
    </xs:sequence>

    <xs:attribute name="Iteration s" default="999999 9"
    type="xs:positi veInteger"/>
    <xs:attribute name="RowName" type="xs:normal izedString"
    default="Record "/>

    </xs:complexType>

    <xs:complexTy pe name="ColSpecTy pe">
    <xs:attribute name="BeginOffs et" type="xs:nonNeg ativeInteger"
    default="0"/>
    <xs:attribute name="EndOffset " type="xs:positi veInteger"/>
    <xs:attribute name="Trim" default="false"
    type="xs:boolea n"/>
    <xs:attribute name="RegExMatc h" type="xs:string "/>
    <xs:attribute name="ColName" type="xs:normal izedString"/>
    </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
  • Martin Honnen

    #2
    Re: What is wrong with this .XSD?



    Casper B wrote:
    [color=blue]
    > I have trouble constructing an .xsd to validate the following simple XML:
    >
    > ------
    > <?xml version = "1.0" encoding="UTF-8"?>
    > <FormatSpec FormatName="Tes t" Encoding="ISO-8859-1" TableName="Reco rdSet"
    > xmlns="http://www.xyz.com"
    > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    > xsi:schemaLocat ion="FormatSpec .xsd">[/color]

    schemaLocation takes at list of white space separated namespaceURIs and
    schema URIs e.g.
    xsi:schemaLocat ion="http://www.xyz.com FormatSpec.xsd"
    [color=blue]
    > <RowSpec Iterations="1">
    > <ColSpec BeginOffset="0" EndOffset="8" RegExMatch="udg start"/>
    > </RowSpec>
    >
    > <RowSpec RowName="Record ">
    > <ColSpec BeginOffset="0" EndOffset="12" ColName="Buildi ngId"/>
    > <ColSpec BeginOffset="17 " EndOffset="21" ColName="StartD ateYear"/>
    > <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="windo ws-1252" ?>
    >
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > xmlns="http://www.xyz.com"
    > targetNamespace ="http://www.xyz.com"
    > elementFormDefa ult="qualified"
    > attributeFormDe fault="qualifie d">[/color]

    Your attributes above are all unqualified (in no namespace) so here you
    should use
    attributeFormDe fault="unqualif ied"


    --

    Martin Honnen

    Comment

    • Priscilla Walmsley

      #3
      Re: What is wrong with this .XSD?

      Hi,

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

      So, it should look like this:

      xsi:schemaLocat ion="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

      ----------------------------------

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Casper B

        #4
        Re: What is wrong with this .XSD?

        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.Parse Exception: 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

        Comment

        • Martin Honnen

          #5
          Re: What is wrong with this .XSD?



          Casper B wrote:

          [color=blue]
          > 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.Parse Exception: 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?[/color]

          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

          Comment

          Working...