Ok, after a lot of google and thanks to the comments of stefan nebesnak, I found two problems that caused the error:
The first, as Stefan noted, is that DBMS_XMLSCHEMA.registerSchema can only be applied to a schema-based document. Initially, what I did in my PL / SQL code was something like this:
l_xml_file_content := XMLType('Here I put the content of my XML document') l_xml_file_content.schemaValidate();
So, as you can see, there is no connection between the registered schema and the XMLType object that references my XML document. I had to do this:
l_xml_file_content := XMLType( 'Here I put the content of my XML document' ).createSchemaBasedXML('and here I put the very same schema URL used during registereation while I registered the schema by calling the DBMS_XMLSCHEMA.registerSchema method')
So, the first problem was resolved, and my XML document became schema based.
The second problem was that in the book, the XML document to be checked against the schema was defined as follows:
<prod:product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:prod="http://datypic.com/prod" xsi:schemaLocation="http://datypic.com/prod prod.xsd" effDate="2011-04-12"> <number>557</number> <size>10</size> </prod:product>
What I understood from " xsi: schemaLocation =" http://datypic.com/prod prod.xsd " was that the first part, that is, http://datypic.com/prod relates to targetNameSpace, and the second part, separated by a space, i.e. prod.xsd , is used to refer to the location (as the URL) of the schema document, which is true, but what I did not know was that in the Oracle DBMS_XMLSCHEMA implementation this second part should be by the same URL that is used to register the schema by calling the DBMS_XMLSCHEMA.RegisterSchema method, otherwise it will not work. And here is a link to the oracle documentation that confirms this:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb03usg.htm#BABBGBDA
If the target XML schema declares the target namespace, then the schemaLocation attribute is used to identify the XML schema. The value of this attribute is a pair of values ββseparated by a space:
- value of the target namespace declared in the XML schema
- schema location hint, unique identifier passed to the DBMS_XMLSCHEMA.registerSchema procedure when the schema is registered in the database
And this is exactly what I did not, I registered the scheme with http://datypic.com/prod , and only because the book had the file name as the second part of xsi: schemaLocation (prod.xsd) I thought that was all what I needed to do was place the contents of the schema in a file named example-01.xsd and then specify the URL of this document, file: ///home/train/Documents/myutl_file_dir/Example-01.xsd . This was really stupid, because when you register a schema with oracle by calling DBMS_XMLSchema.registerSchema, oracle registers the contents of the XML schema document. Thus, what the oracle needs is the schemaURL used during registration, which allows you to uniquely identify and identify a particular scheme. And that was my mistake, I thought the oracle was looking for the physical location of my file.
Conclusion: I registered the scheme with targetNameSpace: 'http://datypic.com/prod' (well, that was just an example, I could choose a different value)
So, the correct schemaLocation value inside my XML document was like this:
xsi:schemaLocation="http://datypic.com/prod prod.xsd http://datypic.com/prod prod.xsd"
And that solved the problem.
Hope this helps those facing the same problem.
Hi,
Dariyoosh