XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
If I want to use catalogs for XSDs, must document instances contain aschemaLocation?

If I want a catalog-aware XML application (such as jEdit with XML plugin, or Altova XMLSpy 2012) to use a catalog to locate XSDs to validate XML document instances, must the XML document instances contain schemaLocation attributes?

I want the answer to be "no", I think the answer is "yes", but I'm not certain.

I had hoped that perhaps these applications might look at the xmlns: attribute values (namespace URIs) in a document instance, and use the catalog to map these namespace URIs to the location of the corresponding XSD files, but that does not work for me in practice.

So, either:
- The answer is "yes" (the document instances must contain schemaLocation attributes)
- The answer is "no", and I'm doing something wrong in my catalog

Here's the start tag of the root element of an example document instance:

<ac:confluence
  xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/"
  xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/"
  xmlns="http://www.atlassian.com/schema/confluence/4/">

and here's the catalog, which is stored in  (note the <public> element referring to a DTD; I'll refer to that soon):

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="public">
<public publicId="-//Atlassian//Confluence 4 Page//EN" uri="confluence.dtd"/>
<uri name="http://www.atlassian.com/schema/confluence/4/ac/" uri="confluence.xsd"/>
<uri name="http://www.atlassian.com/schema/confluence/4/ri/" uri="confluence-ri.xsd"/>
<uri name="http://www.atlassian.com/schema/confluence/4/" uri="confluence-xhtml.xsd"/>
<uri name="http://www.w3.org/XML/1998/namespace" uri="xml.xsd"/>
</catalog>

The document instance and the catalog are stored in completely different paths, on different drives. The .dtd and .xsd files referred to by the catalog are all in the same directory as the catalog.

If I edit this example document instance, the editor is unable to validate it (for example, XMLSpy reports "Unable to locate a reference to a supported schema type (DTD, W3C Schema) within this document instance.").

However, if I add the following DOCTYPE:

<!DOCTYPE ac:confluence PUBLIC "-//Atlassian//Confluence 4 Page//EN" "http://www.atlassian.com/schema/confluence/4/confluence.dtd">

(Note: there is no such DTD at that URI. Neither does the DTD exist in the same directory as the document instance.)

then the editor finds the DTD and can validate the document instance. I mention this to indicate that the editor is successfully using the catalog, at least to locate the DTD (that is, to map the formal public identifier in the DOCTYPE to the local copy of the DTD, in the same directory as the catalog).

If I remove the DOCTYPE, and instead insert the following attributes in the root element:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/confluence.xsd"

then the editor finds the XSD and can validate the document instance (as long as the document instance does not contain character entity references; if it does, the DOCTYPE is also required). That is, the editor looks at the namespace name in the schemaLocation attribute value (URI: http://www.atlassian.com/schema/confluence/4/ac/), and uses the catalog to map that URI to the XSD that is in the same directory as the catalog.

(Note: there is no confluence.xsd in the same directory as the document instance - and, as already mentioned, the catalog is in a completely different path; on a different drive - so the editor must be using the catalog to find the XSD.)

In practice, then, it seems as if the schemaLocation attribute is required if I want to use a catalog to locate the XSD.

But I thought it was worth asking the question, because I would really like to be shown otherwise.

Graham Hannington
Perth, Western Australia

P.S. A digression, not a question - and not involving catalogs - spinning off from my main question...

In case it occurs to anyone to mention it: I know that some applications enable you to explicitly associate a schema with (or "assign a schema to") a document instance, without requiring a schemaLocation attribute. For example, both jEdit and XMLSpy can do this.

I am using XSDs with xmllint to automate the validation of document instances that do not contain schemaLocation attributes. For example (from a Windows .bat file):

for %%f in ("*.xml") do "%_xmllint%" --noent --nowarning --noout --loaddtd --schema "%_schema%" "%%f" >> c:\temp\log.txt 2>&1

where the environment variable _xmllint contains the path of the xmllint executable, and _schema contains the path of the XSD.

In this case, the XML document instances contain the following DOCTYPE:

<!DOCTYPE ac:confluence SYSTEM "confluence.dtd">

and the --loaddtd option instructs xmllint to load the DTD (which, in this case, is in the same directory as the document instance), because the XML document instances can contain character entity references. (xmllint needs to use the DTD to resolve - parse - the character entity references before it can use the XSD to validate).
Fundi Software Pty Ltd 2011 ABN 89 009 120 290
=

This message has been scanned for malware by Websense. www.websense.com



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS