You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Alexander, Karen" <Ka...@documentum.com> on 2002/12/16 22:57:05 UTC

schemaLocation property

Hi,
I'm using Xerces 2.2.1 and I'm trying to validate a document that uses a
schema, but also has a DOCTYPE declaration and internal subset.  I need the
internal subset for some external entity declarations.
 
Does anyone know if it is possible to do this?
 
I've set the  <http://java.sun.com/xml/jaxp/properties/schemaLocation>
http://java.sun.com/xml/jaxp/properties/schemaLocation property, expecting
that the parser will only try to validate against the schema.  However it
appears that the parser is still looking for a DTD.  I get an error message
saying my root element isn't defined :"Element type "root" must be declared.
Line 5, column 102".  My root element is defined in my schema.
 
Here is my XML instance:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root
[<!ENTITY foo "bar">]>
<root xmlns:xsi=" <http://www.w3.org/2001/XMLSchema-instance>
http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
   <sub-level>some &foo; text</sub-level>
</root>

And my schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=" <http://www.w3.org/2001/XMLSchema>
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   <xs:element name="root">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="sub-level" type="xs:string"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>
 
My code looks like this:
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        SAXParser parser = factory.newSAXParser();
        parser.getXMLReader().setErrorHandler(new myHandler());
 
        parser.setProperty("
<http://java.sun.com/xml/jaxp/properties/schemaLanguage>
http://java.sun.com/xml/jaxp/properties/schemaLanguage", "
<http://www.w3.org/2001/XMLSchema> http://www.w3.org/2001/XMLSchema");
        parser.getXMLReader().setFeature("
<http://apache.org/xml/features/validation/schema>
http://apache.org/xml/features/validation/schema", true);
 
        try
        {
            FileInputStream fileInputStream = new
FileInputStream(m_inFileName);
            InputSource inputSource = new InputSource(fileInputStream);
            String uri = new URL("file", "", m_inFileName).toString();
            inputSource.setSystemId(uri);
            parser.getXMLReader().parse(inputSource);
        }
        catch (SAXException e)
        {
            System.out.println(e.getMessage());
            return;
        }
 
If I remove the DOCTYPE declaration from the file (along with the entity
reference), the file parses and validates fine.  The parser is definitely
finding the schema, as I've made a deliberate validation mistake and the
error was reported.
 
Here is the section from the JAXP 1.2 spec that defines this property:
 
http://java.sun.com/xml/jaxp/properties/schemaLanguage 
This property defines the schema language to be used for validation. The
value of this property must be the URI of the schema language specification.
To be compliant with this version of the specification, the implementation
must support the W3C XML schema specification at this URI:
http://www.w3.org/2001/XMLSchema. 

When setValidating is set to true and a schema language is set, then the
parser must validate against that schema language only. For example if an
application sets the schemaLanguage property to XML Schemas then the parser
must try to validate against the XML schema only, even if the document has a
DOCTYPE declaration that refers to a DTD. 

Is there some other property that I need to set to get the parser to expand
my entities, but only validate against the schema?

thanks for any help,
 - Karen 

 

Re: schemaLocation property

Posted by Elena Litani <el...@ca.ibm.com>.
Hi Karen,

> "Alexander, Karen" wrote:
> I'm using Xerces 2.2.1 and I'm trying to validate a document that uses
> a schema, but also has a DOCTYPE declaration and internal subset.  I
> need the internal subset for some external entity declarations.
> 
> Does anyone know if it is possible to do this?

It is not implemented yet. The JAXP code does recognize the property
"schemaLanguage" but in fact it does not do the right thing...

We plan to provide an implemention of JAXP properties in the next
release of Xerces in January.
I will try to let you know when we have this code in CVS.

Thanks,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org