I would like to ask a question about XML document validation against its corresponding XML schema(s) and I would appreciate if you could kindly give me a hand. Actually, I've just started learning about XML schemas (I'm totally a beginner). I've purchased the book "Definitive XML Schema" written by Priscilla Walmsley (2nd Edition) which presents XML Schema 1.1 (which I believe is the most recent version).
Now the problem is that in all examples and exercices of the book, the namespaces and location of the schema files are given using a web URL.
Here is an example of the book:
This is the schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://datypic.com/prod"
xmlns:prod="http://datypic.com/prod">
<xs:element name="product" type="prod:ProductType"/>
<xs:complexType name="ProductType">
<xs:sequence>
<xs:element name="number" type="xs:integer"/>
<xs:element name="size" type="prod:SizeType"/>
</xs:sequence>
<xs:attribute name="effDate" type="xs:date"/>
</xs:complexType>
<xs:simpleType name="SizeType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="2"/>
<xs:maxInclusive value="18"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
And the XML content to be validated against the above mentioned is this
<prod:product xmlns:prod="http://datypic.com/prod"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://datypic.com/prod prod.xsd"
effDate="2011-04-12">
<number>557</number>
<size>10</size>
</prod:product>
Obviously, [http://datypic.com/prod] is a site maintained by the author, so I cannot add or DELETE any file on this site for my exercices while I'm reading this book. As a result I need to put both XML and XSD documents on my local hard drive (I'm using Linux Fedora Core 17 X86_64). So what I did, was to put the content of the schema in a file named for example 'Example-01.xsd' and the XML content in a file named 'Example-01.xml'.
I use oracle PL/SQL package DBMS_XMLSCHEMA (Enterprise Edition 11.2.0.1.0) in order to first register the schema and then call the validate method of XMLType object in order to validate my XML document against the schema, similar to the following link:
https://forums.oracle.com/forums/thread.jspa?messageID=2462207
I have created a directory (by CREATE DIRECTORY) statement in oracle :
/home/train/Documents/myutl_file_dir/
Where I put both my XML & XSD documents. Here is precisely how I changed the above mentioned XML content in order to refer to XSD locally
<prod:product xmlns:prod="http://datypic.com/prod"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://datypic.com/prod file:///home/train/Documents/myutl_file_dir/Example-01.xsd"
effDate="2011-04-12">
<number>557</number>
<size>10</size>
</prod:product>
So if you compare the new XML content with the above mentioned example, the only thing that I added was file:///home/train/Documents/myutl_file_dir/Example-01.xsd at the end of the value of xsi:schemaLocation in order to refer to the local hard drive. I found this method, here:
http://lists.w3.org/Archives/Public/xmlschema-dev/2001Dec/0161.html
Now, the problem is that it doesn't work. When I run my script in order to validate the document by calling the schemaValidate() method of the XMLType object, here is oracle error message:
BEGIN
*
ERROR at line 1:
ORA-19030: Method invalid for non-schema based XML Documents.
ORA-06512: at "SYS.XMLTYPE", line 354
ORA-06512: at "TRAIN2012.ZXML_PKG", line 176
ORA-06512: at line 2
What I understand from the error message 'Method invalid for non-schema based XML Documents' is that oracle has simply ignored the filepath that I defined for schema file and it considers that there has not been any schema declared for this XML document.
Any idea? How can I deal with this problem?
Thanks in advance,
Dariyoosh