You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "David A. Riggs" <dr...@asset.com> on 2001/08/07 16:21:18 UTC
Trouble with 'use' attribute when importing schema namespace
I'm attempting to validate an instance document against
a slightly complicated schema which includes and imports
several smaller ones. I've noticed that attributes
specified use="required" that are referenced from an
imported schema/namespace aren't enforced as I'd expect.
I've included boiled-down examples to better illustrate
below. I'm using JDK 1.3.1 and Xerces-J 1.4.2 and am
trying to validate using one of the included samples,
java -classpath xerces.jar;xercesSamples.jar dom.DOMCount -svnf
instance.xml
Any pointers or feedback would be greatly appreciated!
Thanks,
David A. Riggs
---
The main schema:
-----------------------------
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns = "http://birch.asset.com/example"
targetNamespace = "http://birch.asset.com/example"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
xmlns:driggs="http://driggs.asset.com">
<!-- Import namespace and global attribute from second schema -->
<xsd:import namespace = "http://driggs.asset.com"
schemaLocation = "importedSchema.xsd" />
<xsd:element name="root">
<xsd:complexType>
<!-- This attribute is required, and the parser handles it
properly -->
<xsd:attribute name="LocalRequiredAttribute" use="required"
/>
<!-- This referenced attribute is required, but the parser doesn't
catch it -->
<xsd:attribute ref="driggs:GlobalRequiredAttribute" use="required"
/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
--------------------------------
The imported schema containing the globally defined attribute:
---------------------------------
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns = "http://driggs.asset.com"
targetNamespace = "http://driggs.asset.com"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:attribute name="GlobalRequiredAttribute" />
</xsd:schema>
-----------------------------------
The instance document - should produce errors when validated
since GlobalRequiredAttribute is not present, xerces lists
no errors when parsed and validated:
------------------------------------
<?xml version = "1.0" encoding = "UTF-8"?>
<root xmlns="http://birch.asset.com/example"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://birch.asset.com/example example.xsd"
LocalRequiredAttribute="blah" />
--
David A. Riggs
Science Applications International Corporation - SAIC
(304)284-9000x201 driggs@asset.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Trouble with 'use' attribute when importing schema namespace
Posted by komal mangtani <mk...@bea.com>.
I am not sure whether this is related ( or I am doing something wrong ) but
I am encountering similar kind of problem when importing schema namespace
With xerces 1.3.1 and CR for xml schema when I imported
the standard http://www.w3.org/XML/1998/namespace for use of xml:lang,
it gets parsed perfect when I use xml spy or turbo xml but with xerces
parser it gives error :
"Globally defined attributes should have use= default or fixed "
I do not have any attributes in my xml , so I guess it is refering to
attributes defined in xml.xsd mentioned in schemaLocation in import .
If I do not give schemaLoacation , xerces gives error :
" File "" not found."
Following is the xml snippet :
<xsd:schema xmlns:xsd = "http://www.w3.org/2000/10/XMLSchema"
elementFormDefault = "qualified">
<xsd:import namespace = "http://www.w3.org/XML/1998/namespace"
schemaLocation = "http://www.w3.org/2000/10/xml.xsd"/>
Any pointers ??
Komal.
"David A. Riggs" wrote:
> I'm attempting to validate an instance document against
> a slightly complicated schema which includes and imports
> several smaller ones. I've noticed that attributes
> specified use="required" that are referenced from an
> imported schema/namespace aren't enforced as I'd expect.
>
> I've included boiled-down examples to better illustrate
> below. I'm using JDK 1.3.1 and Xerces-J 1.4.2 and am
> trying to validate using one of the included samples,
>
> java -classpath xerces.jar;xercesSamples.jar dom.DOMCount -svnf
> instance.xml
>
> Any pointers or feedback would be greatly appreciated!
> Thanks,
>
> David A. Riggs
> ---
>
> The main schema:
> -----------------------------
> <?xml version = "1.0" encoding = "UTF-8"?>
> <xsd:schema xmlns = "http://birch.asset.com/example"
> targetNamespace = "http://birch.asset.com/example"
> xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
> xmlns:driggs="http://driggs.asset.com">
>
> <!-- Import namespace and global attribute from second schema -->
> <xsd:import namespace = "http://driggs.asset.com"
> schemaLocation = "importedSchema.xsd" />
>
> <xsd:element name="root">
> <xsd:complexType>
>
> <!-- This attribute is required, and the parser handles it
> properly -->
> <xsd:attribute name="LocalRequiredAttribute" use="required"
> />
>
> <!-- This referenced attribute is required, but the parser doesn't
> catch it -->
> <xsd:attribute ref="driggs:GlobalRequiredAttribute" use="required"
> />
>
> </xsd:complexType>
> </xsd:element>
>
> </xsd:schema>
> --------------------------------
> The imported schema containing the globally defined attribute:
> ---------------------------------
> <?xml version = "1.0" encoding = "UTF-8"?>
> <xsd:schema xmlns = "http://driggs.asset.com"
> targetNamespace = "http://driggs.asset.com"
> xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
>
> <xsd:attribute name="GlobalRequiredAttribute" />
>
> </xsd:schema>
> -----------------------------------
> The instance document - should produce errors when validated
> since GlobalRequiredAttribute is not present, xerces lists
> no errors when parsed and validated:
> ------------------------------------
> <?xml version = "1.0" encoding = "UTF-8"?>
> <root xmlns="http://birch.asset.com/example"
> xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation = "http://birch.asset.com/example example.xsd"
>
> LocalRequiredAttribute="blah" />
>
> --
> David A. Riggs
> Science Applications International Corporation - SAIC
> (304)284-9000x201 driggs@asset.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org