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 vkoro <vi...@gmail.com> on 2008/10/08 14:51:27 UTC

Validating XML file using catalogs

My xml file has DOCTYPE with entities. Something like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ss:manifest [
<!ENTITY ent1 "http://some1.com/qqq/qqqq/">
<!ENTITY ent2 "http://some2.com/qqq/qqqq/">]>
<ss:manifest ss:version="1.0" 
    xmlns:ss="http://some3.com/www/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://some3.com/www/ some.xsd">
    <ss:prolog> .....


I validate it using catalog

      XMLCatalogResolver resolver = new XMLCatalogResolver();
      resolver.setCatalogList(new
String[]{"C:\\Project\\parser\\xml\\catalog.xml"});

      SAXParserFactory factory = SAXParserFactory.newInstance();
      factory.setNamespaceAware(true);

      SAXParser parser = factory.newSAXParser();
     
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", 
                                "http://www.w3.org/2001/XMLSchema");

      XMLReader reader = parser.getXMLReader();
     
reader.setProperty("http://apache.org/xml/properties/internal/entity-resolver",
resolver);
      reader.setFeature("http://apache.org/xml/features/validation/schema",
true);
      reader.setFeature("http://xml.org/sax/features/validation", true);
      
      reader.parse(new InputSource(new
FileInputStream("C:\\Project\\parser\\xml\\manifest.xml")));

Somehow when DOCTYPE  is in the xml the reader stops using schema for
validation. It just cannot find it.
As soon as DOCTYPE is removed the problem disappears

Could anybody suggest how to make it use schema when DOCTYPE is declared ?

Thank you




-- 
View this message in context: http://www.nabble.com/Validating-XML-file-using-catalogs-tp19877883p19877883.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


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


Re: Validating XML file using catalogs

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi,

In the snippet you posted you're passing an input to the parser without
specifying a base URI for the XML document. You should always specify one
(i.e. call InputSource.setSystemId()) otherwise relative URIs such as the
one you specified in the xsi:schemaLocation attribute get resolved against
the current working directory which may not actually be where your schema
document is.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

vkoro <vi...@gmail.com> wrote on 10/08/2008 08:51:27 AM:

> My xml file has DOCTYPE with entities. Something like this
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE ss:manifest [
> <!ENTITY ent1 "http://some1.com/qqq/qqqq/">
> <!ENTITY ent2 "http://some2.com/qqq/qqqq/">]>
> <ss:manifest ss:version="1.0"
>     xmlns:ss="http://some3.com/www/"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="http://some3.com/www/ some.xsd">
>     <ss:prolog> .....
>
>
> I validate it using catalog
>
>       XMLCatalogResolver resolver = new XMLCatalogResolver();
>       resolver.setCatalogList(new
> String[]{"C:\\Project\\parser\\xml\\catalog.xml"});
>
>       SAXParserFactory factory = SAXParserFactory.newInstance();
>       factory.setNamespaceAware(true);
>
>       SAXParser parser = factory.newSAXParser();
>
>
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",

>                                 "http://www.w3.org/2001/XMLSchema");
>
>       XMLReader reader = parser.getXMLReader();
>
>
reader.setProperty("http://apache.org/xml/properties/internal/entity-resolver

> ",
> resolver);
>
reader.setFeature("http://apache.org/xml/features/validation/schema",
> true);
>       reader.setFeature("http://xml.org/sax/features/validation", true);
>
>       reader.parse(new InputSource(new
> FileInputStream("C:\\Project\\parser\\xml\\manifest.xml")));
>
> Somehow when DOCTYPE  is in the xml the reader stops using schema for
> validation. It just cannot find it.
> As soon as DOCTYPE is removed the problem disappears
>
> Could anybody suggest how to make it use schema when DOCTYPE is declared
?
>
> Thank you
>
>
>
>
> --
> View this message in context: http://www.nabble.com/Validating-XML-
> file-using-catalogs-tp19877883p19877883.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org