correct use of xsi:schemaLocation

S

Sarah Tegtmeier

Hi

I have a question about the correct use of the attribute
xsi:schemaLocation. My programm has to process XML files where the value of
this attribute causes some problems. The programm is written in C++
using Xerces C++ version 2.3.0. An older older version of the programm
used Xerces C++ version 1.6.0.

The XML files look like the following example:

example.xml
============
<an:root xmlns:an="nsAnton"
xmlns:bt="nsBerta"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="nsBerta antonFile.xsd">
<!-- content -->
</an:root>

The schema definitions files used by example.xml are

antonFile.xsd
==============
<schema targetNamespace="nsAnton">
<include schemaLocation="nsAnton.xsd"/>
<import namespace="nsBerta" schemaLocation="nsBerta.xsd"/>
</schema>

nsAnton.xsd
============
<schema targetNameSpace="nsAnton">
<element name="root">
<!-- content of root-element -->
</element>
</schema>

nsBerta.xsd
============
<schema targetNamespace="nsBerta">
<!-- vocabularry of schema nsBerta -->
</schema>

When I validate file example.xml with a SAX parser using Xerces C++
version 1.6.0 the file is recognized as valid. xmlspy (professional
edition version 5, release 4) also tells me that the file is valid.
But when i run a SAX parser using Xerces C++ verion 2.3.0 i got the
message
"Schema in antonFile.xsd has a different target namespace
from the one specified in the instance document nsBerta."
and the file is considered as invalid.

So i have two validation results one from Xerces C++ 1.6.0 and xmlspy
5.4 and one from Xerces C++ 2.3.0. But which one is correct?
When I change the value of the schema location attribute to

xsi:schemaLocation="nsAnton antonFile.xsd"

the file is considered as valid by all of the three parsers. Hence the
two different validation results of file example.xml are caused by

xsi:schemaLocation="nsBerta antonFile.xsd"

in my opinion the classification of Xerces C++ 2.3.0 is correct
because the target namespace of antonFile.xsd is nsAnton and not
nsBerta. I would expect that the target namepace of the schema
defintion file must match the namespace to which the schema definition
file is connected by the attribute xsi:schemaLocation, i.e. in

xsi:schemaLocation="namespace namespaceFile.xsd"

the condition

namespace == TARGET-NAMESPACE ( namespaceFile.xsd )

must be satisfied.

Is my interpretation correct?

The W3C recommendation (http://www.w3.org/TR/xmlschema-1/) states that
the value of the attribute xsi:schemaLocation gives only a hint where an
application can find the definition of a namespace but an application
must not use this information.

I would appreciate information about the correct use of the attribute
xsi:schemaLocation.

yours sincerely

Sarah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top