What is wrong with this .XSD?

C

Casper B

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
 
M

Martin Honnen

Casper said:
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"
 
P

Priscilla Walmsley

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
 
C

Casper B

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
 
M

Martin Honnen

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.
 

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

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top