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 Vitor Carreira <vi...@gmail.com> on 2007/03/19 14:33:02 UTC
XML validation using a external schema local copy
Hi,
I'm trying to validate a XML document against a copy of an external schema.
The XML document, called portlet.xml start with the following code:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
I've download the schema from
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd and stored in a
file called portlet.xsd.
The code for my spike is the following:
DOMParser portletParser = new DOMParser();
portletParser.setFeature("http://xml.org/sax/features/validation", true);
portletParser.setFeature("http://apache.org/xml/features/validation/schema",
true);
String portletXSDLocation = new File("portlet.xml").toURL().toExternalForm();
portletParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
portletXSDLocation);
portletParser.setErrorHandler(myErrorHandler);
InputSource source = new InputSource(new FileInputStream("portlet.xml"));
parser.parse(source);
The code above doesn't work as expected. If I'm behind a firewall the
DOMParser doesn't use the XSD local copy and always tries to fetch the
xsd from http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd.
Any ideas how to validate a XML document using a local copy of an
external schema?
Thanks,
Vítor
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: XML validation using a external schema local copy
Posted by Vitor Carreira <vi...@gmail.com>.
Michael,
thank you very much. Problem solved setting the property
correctly: portletParser.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation",
"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd " +
new File("portlet.xsd").toURL().toExternalForm() +
" http://www.w3.org/XML/1998/namespace " +
new File("xml.xsd").toURL().toExternalForm());
The last namespace is necessary because of the import statement inside
the portlet.xsd schema.
Once again
Thank you very much,
Vitor
On 3/19/07, Michael Glavassevich <mr...@ca.ibm.com> wrote:
> Hi Vitor,
>
> The external schema location properties have the same definitions as the
> ones defined in the schema spec [1]. The value of external-schemaLocation
> is a list of pairs of URIs, where the first of each pair is a target
> namespace and the second of each pair is a schema location hint. You've
> only specified the schemaLocation. It needs to be preceded by a target
> namespace (i.e. http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd).
>
> Thanks.
>
> [1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#schema-loc
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Vitor Carreira" <vi...@gmail.com> wrote on 03/19/2007 09:33:02
> AM:
>
> > Hi,
> >
> > I'm trying to validate a XML document against a copy of an external
> schema.
> >
> > The XML document, called portlet.xml start with the following code:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <portlet-app
> > xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
> > version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="
> http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
> > http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
> >
> >
> > I've download the schema from
> > http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd and stored in a
> > file called portlet.xsd.
> >
> > The code for my spike is the following:
> >
> > DOMParser portletParser = new DOMParser();
> > portletParser.setFeature("http://xml.org/sax/features/validation",
> true);
> > portletParser.setFeature("
> http://apache.org/xml/features/validation/schema",
> > true);
> >
> > String portletXSDLocation = new
> File("portlet.xml").toURL().toExternalForm();
> > portletParser.setProperty("http://apache.
> > org/xml/properties/schema/external-schemaLocation",
> > portletXSDLocation);
> > portletParser.setErrorHandler(myErrorHandler);
> >
> > InputSource source = new InputSource(new FileInputStream("portlet.
> > xml"));
> > parser.parse(source);
> >
> > The code above doesn't work as expected. If I'm behind a firewall the
> > DOMParser doesn't use the XSD local copy and always tries to fetch the
> > xsd from http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd.
> >
> > Any ideas how to validate a XML document using a local copy of an
> > external schema?
> >
> > Thanks,
> >
> > Vítor
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: XML validation using a external schema local copy
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Vitor,
The external schema location properties have the same definitions as the
ones defined in the schema spec [1]. The value of external-schemaLocation
is a list of pairs of URIs, where the first of each pair is a target
namespace and the second of each pair is a schema location hint. You've
only specified the schemaLocation. It needs to be preceded by a target
namespace (i.e. http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd).
Thanks.
[1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#schema-loc
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
"Vitor Carreira" <vi...@gmail.com> wrote on 03/19/2007 09:33:02
AM:
> Hi,
>
> I'm trying to validate a XML document against a copy of an external
schema.
>
> The XML document, called portlet.xml start with the following code:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <portlet-app
> xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
> version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
> http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
>
>
> I've download the schema from
> http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd and stored in a
> file called portlet.xsd.
>
> The code for my spike is the following:
>
> DOMParser portletParser = new DOMParser();
> portletParser.setFeature("http://xml.org/sax/features/validation",
true);
> portletParser.setFeature("
http://apache.org/xml/features/validation/schema",
> true);
>
> String portletXSDLocation = new
File("portlet.xml").toURL().toExternalForm();
> portletParser.setProperty("http://apache.
> org/xml/properties/schema/external-schemaLocation",
> portletXSDLocation);
> portletParser.setErrorHandler(myErrorHandler);
>
> InputSource source = new InputSource(new FileInputStream("portlet.
> xml"));
> parser.parse(source);
>
> The code above doesn't work as expected. If I'm behind a firewall the
> DOMParser doesn't use the XSD local copy and always tries to fetch the
> xsd from http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd.
>
> Any ideas how to validate a XML document using a local copy of an
> external schema?
>
> Thanks,
>
> Vítor
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org