What is wrong with this .XSD?

Casper B

Usenet Archive
Joined
Dec 17, 2004
Messages
8
Reaction score
0
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
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
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"
 

Priscilla Walmsley

Usenet Archive
Joined
Apr 15, 2004
Messages
77
Reaction score
0
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
 

Casper B

Usenet Archive
Joined
Dec 17, 2004
Messages
8
Reaction score
0
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
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top