Problems validating XML file against Schema

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
ychaikin
Posts: 20
Joined: Thu Sep 09, 2004 9:23 pm

Problems validating XML file against Schema

Post by ychaikin » Thu Sep 09, 2004 9:55 pm

Hi,

I just got OxygenXML and was all excited about it, when I realized that it's not validating an XML file properly. :(
I must be doing something wrong since I can't imagine that something that's based on Xerces-J is not following the spec.

These files validate 100% in XMLSpy, by the way.

Here is the XML file (store.xml):

Code: Select all


<?xml version="1.0"?>
<!DOCTYPE store SYSTEM "store.dtd">
<store
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.apl.jhu.edu/~davids/605742/"
xsi:noNamespaceSchemaLocation="store.xsd">

<cust_list>
<customer cid="C-1" >
<name title="Mr.">
<first>Sam</first>
<middle>Ta</middle>
<middle>Chuan</middle>
<last>Chu</last>
</name>
<address>
<street>123-A Kensington Circle</street>
<city>London</city><country>England</country>
</address>
<purchase date="2002-01-12" items="I-34 I-62 I-15" qty="3 1 1" />
<purchase date="2002-01-13" items="I-15" qty="2" />
</customer>
<customer cid="C-2" ctype="bad">
<name title="Dr.">
<first>Darsana</first>
<last>Sudarsen</last>
</name>
<address>
<street>11100 Johns Hopkins</street>
<city>Baltimore</city><state>MD</state>
<zip>21207</zip>
</address>
<purchase date="2002-02-02" items="I-62 I-5" qty="2 1" />
</customer>
</cust_list>
<inventory_list>
<item item_no="I-5" supplier_id="S-1">
<description>Ivory Soap</description>
<in_stock>50</in_stock>
<price>1.09</price>
<cost>.28</cost>
</item>
<item item_no="I-15" supplier_id="S-1">
<description>Cheer Detergent</description>
<in_stock>37</in_stock>
<price>5.98</price>
<cost>2.10</cost>
</item>
<item item_no="I-34" supplier_id="S-1">
<description>Bounty Paper Towels</description>
<in_stock>112</in_stock>
<price>1.48</price>
<cost>.57</cost>
</item>
<item item_no="I-62" supplier_id="S-2">
<description>Sunshine Tissues</description>
<in_stock>320</in_stock>
<price>1.65</price>
<cost>.98</cost>
</item>
</inventory_list>
<supplier_list>
<supplier sid="S-1">
<company>Proctor and Gamble</company>
<telephone>1-800-PAMPERS</telephone>
</supplier>
<supplier sid="S-2">
<company>Sunshine Products</company>
<telephone>1-888-344-9881</telephone>
</supplier>
</supplier_list>
</store>
Here is the XSD file (store.xsd):

Code: Select all


<?xml version="1.0"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://www.apl.jhu.edu/~davids/605742/"
xmlns:store="http://www.apl.jhu.edu/~davids/605742/">

<element name="store" type="store:StoreType"/>
<simpleType name="ProperName">
<restriction base="string">
<pattern value="[A-Z][a-zA-Z]*"/>
</restriction>
</simpleType>
<simpleType name="MixedName">
<restriction base="string">
<pattern value="[\sa-zA-Z0-9-]*"/>
</restriction>
</simpleType>
<complexType name="StoreType">
<all>
<element name="cust_list" type="store:CustListType" minOccurs="0"/>
<element name="inventory_list" type="store:InventoryListType" minOccurs="0"/>
<element name="supplier_list" type="store:SupplierListType" minOccurs="0"/>
</all>
</complexType>
<complexType name="CustListType">
<sequence>
<element name="customer" type="store:CustomerType" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="CustomerType">
<sequence>
<element name="name">
<complexType>
<sequence>
<element name="first" type="store:ProperName"/>
<element name="middle" type="store:ProperName" minOccurs="0" maxOccurs="unbounded"/>
<element name="last" type="store:ProperName"/>
</sequence>
<attribute name="title" type="store:Title" use="optional" default="Ms."/>
</complexType>
</element>
<element name="address" type="store:AddressType"/>
<element name="purchase" minOccurs="0" maxOccurs="unbounded">
<complexType>
<attribute name="date" type="date"/>
<attribute name="items" type="IDREFS"/>
<attribute name="qty" type="store:IntegerList"/>
</complexType>
</element>
</sequence>
<attribute name="cid" type="ID"/>
<attribute name="ctype" type="string" use="optional" default="good"/>
</complexType>
<simpleType name="IntegerList">
<list itemType="integer"/>
</simpleType>
<simpleType name="Title">
<restriction base="string">
<enumeration value="Mr."/>
<enumeration value="Ms."/>
<enumeration value="Mrs."/>
<enumeration value="Miss"/>
<enumeration value="Dr."/>
</restriction>
</simpleType>
<group name="USAddressGroup">
<sequence>
<element name="state" type="store:USState"/>
<element name="zip" type="store:ZipCode"/>
</sequence>
</group>
<complexType name="AddressType">
<sequence>
<element name="street" type="store:MixedName"/>
<element name="city" type="store:ProperName"/>
<choice>
<element name="country" type="store:ProperName"/>
<group ref="store:USAddressGroup"/>
</choice>
</sequence>
</complexType>
<simpleType name="ZipCode">
<restriction base="string">
<pattern value="[0-9]{5}"/>
</restriction>
</simpleType>
<simpleType name="USState">
<restriction base="string">
<enumeration value="AK"/>
<enumeration value="AL"/>
<enumeration value="MD"/>
</restriction>
</simpleType>
<complexType name="InventoryListType">
<sequence>
<element name="item" type="store:ItemType" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="ItemType">
<all>
<element name="description" type="string"/>
<element name="in_stock" type="nonNegativeInteger"/>
<element name="price" type="decimal"/>
<element name="cost" type="decimal"/>
</all>
<attribute name="item_no" type="ID"/>
<attribute name="supplier_id" type="IDREF"/>
</complexType>
<simpleType name="StdTelNum">
<restriction base="string">
<pattern value="\d{1}-\d{3}-\d{3}-\d{4}"/>
</restriction>
</simpleType>
<simpleType name="StringTelNum">
<restriction base="string">
<pattern value="\d{1}-\d{3}-[A-Z0-9]{7}"/>
</restriction>
</simpleType>
<simpleType name="AllTelNum">
<union memberTypes="store:StdTelNum store:StringTelNum"/>
</simpleType>
<complexType name="SupplierListType">
<sequence>
<element name="supplier" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="company" type="store:MixedName"/>
<element name="telephone" type="store:AllTelNum"/>
</sequence>
<attribute name="sid" type="ID"/>
</complexType>
</element>
</sequence>
</complexType>
</schema>
Here is the DTD file (store.dtd) (which actually does validate fine, but I am including it here for completeness since it's referenced in the XML):

Code: Select all


<!ELEMENT store (cust_list, inventory_list, supplier_list) >
<!ATTLIST store
xmlns:xsi CDATA #FIXED "http://www.w3.org/2001/XMLSchema-instance"
xmlns CDATA #FIXED "http://www.apl.jhu.edu/~davids/605742/"
xsi:noNamespaceSchemaLocation CDATA #REQUIRED>

<!ELEMENT cust_list (customer+) >

<!ELEMENT customer (name, address, purchase*) >
<!ATTLIST customer
cid ID #REQUIRED
ctype NMTOKEN #IMPLIED>

<!ELEMENT name (first, middle*, last) >

<!ATTLIST name title (Dr. | Mr. | Ms. | Miss) #IMPLIED>
<!ELEMENT first (#PCDATA) >
<!ELEMENT middle (#PCDATA) >
<!ELEMENT last (#PCDATA) >

<!ELEMENT address (street+, city, (country | (state, zip)))>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zip (#PCDATA)>

<!ELEMENT purchase EMPTY >
<!ATTLIST purchase
date CDATA #IMPLIED
items IDREFS #REQUIRED
qty NMTOKENS #REQUIRED >


<!ELEMENT inventory_list (item+) >

<!ELEMENT item (description, in_stock, price, cost) >
<!ATTLIST item
item_no ID #REQUIRED
supplier_id IDREF #REQUIRED >

<!ELEMENT description (#PCDATA)>
<!ELEMENT in_stock (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT cost (#PCDATA)>

<!ELEMENT supplier_list (supplier+) >

<!ELEMENT supplier (company, telephone) >
<!ATTLIST supplier
sid ID #REQUIRED>

<!ELEMENT company (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>


Here are the error messages I get when I try to hit "Validate" botton for the store.xsd:

E src-resolve.4.2: Error resolving component 'store:StoreType'. It was detected that 'store:StoreType' is in namespace 'http://www.apl.jhu.edu/~davids/605742/', but components from this namespace are not referenceable from schema document 'file:/C:/temp/store.xsd'. If this is the incorrect namespace, perhaps the prefix of 'store:StoreType' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/C:/temp/store.xsd'. store.xsd file:/C:/temp/store.xsd 8:48E InvalidRegex: Pattern value '[\sa-zA-Z0-9-]*' is not a valid regular expression. The reported error was: ''-' is an invalid character range. Write '\-'.'. store.xsd file:/C:/temp/store.xsd 15:30E src-resolve: Cannot resolve the name 'store:Title' to a(n) 'simpleType definition' component. store.xsd file:/C:/temp/store.xsd 40:79E src-resolve: Cannot resolve the name 'store:IntegerList' to a(n) 'simpleType definition' component. store.xsd file:/C:/temp/store.xsd 48:54



Here are the error messages I get when I hit the validate botton for the store.xml:

E cvc-elt.1: Cannot find the declaration of element 'store'. store.xml file:/C:/temp/store.xml 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1E TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://www.apl.jhu.edu/%7Edavids/605742/'. store.xsd file:/C:/temp/store.xsd 6:1

Can someone point out to me what I am setting up wrong in OxygenXML? I am pretty sure that the errors it's showing to me are wrong. These files comply with the XML spec.

Just to give you a specific example. OxygenXML is complaining about a regular expression for this line:

Code: Select all


<pattern value="[\sa-zA-Z0-9-]*"/>
It says that "-" has to be specified by "\-". This is not true according to the spec:
http://www.w3.org/TR/xmlschema-0/#regexAppendix


Thanks,
Yaakov.

george
Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Fri Sep 10, 2004 3:05 pm

Hi Yakoov,

The schema/@targetNamespace is defined as having anyURI type [1]. Now what is important is the *actual value* [2] of the targetNamespace. You can look further at [3] and see that in order to get the URI defined by the attribute there is a mapping of special characters defined in [4] and [5]. In [5] you can see also an example
Example: The string "http://www.w3.org/People/Dürst/" is not a legal URI because the character "ü" is not allowed in URIs. The representation of "ü" in UTF-8 consists of two bytes with the values 0xC3 and 0xBC. The string is therefore converted to "http://www.w3.org/People/D%C3%BCrst/".
In your case the http://www.apl.jhu.edu/~davids/605742/ will get http://www.apl.jhu.edu/%7Edavids/605742/. It is true that the ~ character has an ambigous status with respect to replacing it with %7E, both representations are allowed. Oxygen uses Xerces for processing XML Schemas and it replaces ~ with %7E.
If you change the schema to specify this in the namespace mapping
xmlns:store="http://www.apl.jhu.edu/%7Edavids/605742/"
then you will not have the errors that mention that some types are not found. You will still have however the error related with the "-" character in the pattern value: [\sa-zA-Z0-9-]*

Following exactly the link you quoted in your post you can get a little further to [6] where you can see that if you want to use the "-" character in a pattern without having a special menaning (that is range indicator) then you have to escape it as "\-":
The valid single character escapes are:
[...]
\-
Fixing the pattern value as <pattern value="[\sa-zA-Z0-9\-]*"/> will get the schema valid and also oXygen will report it valid.

Now moving to your instance document. You have associated the schema using the xsi:noNamespaceSchemaLocation attribute but your schema has a target namespace and in this case you should use the xsi:schemaLocation attribute instead. Correcting also the default namespace value to match the targetNamespace actual value will get:

Code: Select all


<store
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.apl.jhu.edu/%7Edavids/605742/"
xsi:schemaLocation="http://www.apl.jhu.edu/%7Edavids/605742/ store.xsd">
and the instance document will be reported valid.

[1] http://www.w3.org/TR/xmlschema-1/#Schema_details
[2] http://www.w3.org/TR/xmlschema-1/#key-vv
[3] http://www.w3.org/TR/xmlschema-2/#anyURI
[4] http://www.w3.org/TR/2000/PR-xlink-2000 ... k-locators
[5] http://www.w3.org/TR/2001/WD-charmod-20010126/#sec-URIs
[6] http://www.w3.org/TR/2001/REC-xmlschema ... gleCharEsc

Hope that helps,
George

ychaikin
Posts: 20
Joined: Thu Sep 09, 2004 9:23 pm

Post by ychaikin » Fri Sep 10, 2004 4:46 pm

George,

Thanks for your reply. Makes sense. I'll try to fix the files and see what happens.

As far as the "-" goes, can you then explain why the spec show this as valid example (from my original link):
[-ae]x this will validate: -x, ax, ex

Why didn't they put a "\-" there?

Thanks,
Yaakov.

george
Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Fri Sep 10, 2004 5:36 pm

Hi Yaakov,

That is an error in the specification.
See the errata for this:
http://www.w3.org/2001/05/xmlschema-errata#e0-11

Hope that helps,
George

ychaikin
Posts: 20
Joined: Thu Sep 09, 2004 9:23 pm

Post by ychaikin » Sun Sep 12, 2004 5:39 am

George,

That's unbelievable! They didn't correct it right there, but put it somewhere else in some "errors page". :shock:

Thank you so much for pointing that out to me.

Yaakov.

Post Reply