Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > What is wrong with this .XSD?

Reply
Thread Tools

What is wrong with this .XSD?

 
 
Casper B
Guest
Posts: n/a
 
      03-02-2005
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"
xmlnssi="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 xmlnss="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="xsositiveInteger"/>
<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="xsositiveInteger"/>
<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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-02-2005


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"
> xmlnssi="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 xmlnss="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/
 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      03-02-2005
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!
 
Reply With Quote
 
Casper B
Guest
Posts: n/a
 
      03-02-2005
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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      03-02-2005


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments