Created Monday 19 September 2011
This is the DocBook sample_article.xml
I'd like validating:
<?xml version='1.0' encoding='UTF-8'?>
<article version="5.0" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="
http://docbook.org/ns/docbook
http://docbook.org/xml/5.0/xsd/docbook.xsd">
<title>Sample article</title>
<para>This is a very short article.</para>
</article>
I've tried validating sample_article.xml In NetBeans:
unfortunately NetBeans logs:
XML validation started. Checking file:/C:/sample_article.xml... Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". Referenced entity at "http://docbook.org/xml/5.0/xsd/xlink.xsd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/XMLSchema.dtd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/datatypes.dtd". src-resolve: Cannot resolve the name 'xml:id' to a(n) 'attribute declaration' component. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd s4s-elt-must-match.1: The content of 'db.common.attributes' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attribute. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd cvc-complex-type.3.2.2: Attribute 'version' is not allowed to appear in element 'article'. [6] cvc-complex-type.3.2.2: Attribute 'xml:lang' is not allowed to appear in element 'article'. [6] XML validation finished.
But wait a moment! Where does NetBeans get docbook.xsd?
If I disconnect my PC from Internet, and I retry validating
the sample_article.xml again, NetBeans logs:
XML validation started. Checking file:/C:/sample_article.xml... Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". schema_reference.4: Failed to read schema document 'http://docbook.org/xml/5.0/xsd/docbook.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. [6] cvc-elt.1: Cannot find the declaration of element 'article'. [6] Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". schema_reference.4: Failed to read schema document 'http://docbook.org/xml/5.0/xsd/docbook.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. [7] Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". schema_reference.4: Failed to read schema document 'http://docbook.org/xml/5.0/xsd/docbook.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. [8] XML validation finished.
Clearly NetBeans validates sample_article.xml
against the
http://docbook.org/xml/5.0/xsd/docbook.xsd
file on Internet, but something goes wrong.
So I've decided to investigate using a DocBook 5.0
local copy.
I've downloaded the docbook-5.0.zip from the
DocBook 5.0 distribution page
,
and I've expanded it in a NetBeans project.
Than I've disconnected my PC from Internet and
I've said to NetBeans where I've expanded the
docbook.xsd file by the
Tools > DTDs and XML Schemas menu:
Then I've added a local schema under the User Catalog:
binding the http://docbook.org/xml/5.0/xsd/docbook.xsd
URI location to the actual docbook.xsd
file location by the System ID button:
Trying re-validating the sample_article.xml
NetBeans logs the previously seen error:
XML validation started. Checking file:/C:/sample_article.xml... Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". Referenced entity at "http://docbook.org/xml/5.0/xsd/xlink.xsd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/XMLSchema.dtd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/datatypes.dtd". src-resolve: Cannot resolve the name 'xml:id' to a(n) 'attribute declaration' component. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd s4s-elt-must-match.1: The content of 'db.common.attributes' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attribute. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd cvc-complex-type.3.2.2: Attribute 'version' is not allowed to appear in element 'article'. [6] cvc-complex-type.3.2.2: Attribute 'xml:lang' is not allowed to appear in element 'article'. [6] XML validation finished.
Finally I've set up a DocBook 5.0 local copy and I've recreated the on-line error, so I'm ready to investigate.
In the docbook-5.0\xsd\ directory
there's the docbook.xsd. At line 6
there's: <xs:attribute ref="xml:id"/>
It seams NetBeans isn't able to locate the xml.xsd
in the docbook-5.0\xsd\ directory even
if docbook.xsd declares at line 4:
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
By the way... I've bound the xml.xsd URI
location to the actual xml.xsd file location
as I've still done before:
so I've ended up with the two cataloged xsd:
the docbook.xsd and the xml.xsd.
Trying re-validating the sample_article.xml
NetBeans logs the previously seen error again:
XML validation started. Checking file:/C:/sample_article.xml... Referenced entity at "http://docbook.org/xml/5.0/xsd/docbook.xsd". Referenced entity at "http://docbook.org/xml/5.0/xsd/xlink.xsd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/XMLSchema.dtd". Referenced entity at "nbres:/org/netbeans/modules/j2ee/ddloaders/catalog/resources/datatypes.dtd". src-resolve: Cannot resolve the name 'xml:id' to a(n) 'attribute declaration' component. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd s4s-elt-must-match.1: The content of 'db.common.attributes' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attribute. [6] http://docbook.org/xml/5.0/xsd/docbook.xsd cvc-complex-type.3.2.2: Attribute 'version' is not allowed to appear in element 'article'. [6] cvc-complex-type.3.2.2: Attribute 'xml:lang' is not allowed to appear in element 'article'. [6] XML validation finished.
I've tried several URI combined with various
User Catalog and
Catalog Resolver but, in my opinion,
there's something wrong in how NetBeans binds URI
location to actual file location. I suppose NetBeans
tries getting the file only if its URI has the
form of an URL, downloading the file from Internet,
while if the file hasn't the URL form NetBeans
doesn't try interpreting the URL as a relative pathname
to an actual file.
I've found a
solved bug
but I'm not sure that is completely solved, as
someone else has commented.
This is the workaround I've came up to get DocBook 5.0 validation working in Netbeans 7.0.1. The idea is based on the facts investigated in the Investigating section above: NetBeans succesfully resolves URI only if they are in a URL form.
Before going on, if you've done what I did in the
preceding sections, remove docbook.xsd
and xml.xsd from
User Catalog.
Firstly download the docbook-5.0.zip from the
DocBook 5.0 distribution page
,
and expand it in a NetBeans project (probably
you may like a project that builds a
docbook-xml-5.0-wrapper.jar).
Then in the docbook-5.0\xsd\docbook.xsd
file change URI schema locations from the relative
pathname form:
<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd" /> <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd" />
to the URL form:
<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://docbook.org/xml/5.0/xsd/xlink.xsd" /> <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://docbook.org/xml/5.0/xsd/xml.xsd" />
Now put the
systemCatalog.xml
I've created in the same directory in which there's the
docbook-5.0 folder of the DocBook 5.0
distribution:
Finally add a catalog resolver for the just added
systemCatalog.xml:
Trying re-validating the sample_article.xml
NetBeans successfully logs:
XML validation started. Checking file:/C:/sample_article.xml... XML validation finished.
Copyright © 2003, 2012 Tarin Gamberini
Ultimo aggiornamento 01/11/2011