Hello,
Everything is working now, an instance doc for a different device type was
wrong, and this is what Xerces (which rocks !) was reporting during
validation in init()

Thanks
----- Original Message -----
From: "Siarhei Biarozkin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 24, 2002 10:45 AM
Subject: Re: Validating schema file with target namespace?


> Hello,
>
> After spending few days and nights (:-)) on tracing the problem with the
> validation, I've finally got it working, with and without registering
> EntityResolver. The following code validates an instance against the
schema,
> and I'm nearly  happy about it (please see more after the code fragment on
> this) :
>
> // start of code
> // I've only added :
> reader.setFeature("http://xml.org/sax/features/namespaces";, true);
> // I thought the default was true...
>
> String configPath = "/WEB-INF/devices/" + deviceType +
> "/config/devices.xml";
> InputSource configStream = new InputSource(new BufferedInputStream(
>
getServletContext().
>
> getResourceAsStream(configPath)));
>
>
configStream.setSystemId(getServletContext().getResource(configPath).toStrin
> g());
>
>  SAXParserFactory factory = SAXParserFactory.newInstance();
> SAXParser parser = factory.newSAXParser();
> XMLReader reader = parser.getXMLReader();
>
>  try {
>              reader.setFeature("http://xml.org/sax/features/namespaces";,
> true);
>              reader.setFeature("http://xml.org/sax/features/validation";,
> true);
>
>
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage";,
>                                "http://www.w3.org/2001/XMLSchema";);
>             } catch (Exception e) {
>                 System.err.println("Cannot activate validation." +
> e.getMessage());
>             }
>
>             ConfigContentHandler handler = new ConfigContentHandler();
>             reader.setContentHandler(handler);
>             reader.setErrorHandler(handler);
>             //reader.setEntityResolver(handler);
>             reader.parse(configStream);
> // end of code
>
> The only problem is that this code works fine when invoked from within a
> method like Servlet.doGet(), but doesn't work when called within
> Servlet.init(), the exception thrown in this case is
> cvc-elt.1 : Cannot find the declaration of element 'Devices'
>
> even though my instance's root element is declared as "dev:Devices".
>
>
> Should I set some other feature/property on the parser ?
>
> Thanks
> Sergey Beryozkin
> ----- Original Message -----
> From: "Siarhei Biarozkin" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, September 19, 2002 10:33 AM
> Subject: Re: Validating schema file with target namespace?
>
>
> > Hello Eddie,
> > I'm still confusing everyone with my example, my apologies.
> > The value of a schemaLocation attribute's (schema part) is identical to
> the
> > namespace defined on the element, honestly :-), I'm using a slightly
> > different namespace in my project which is
> "http://www.zandar.com/control/";.
> > I've always thought that setting systemId is what is required for a
> default
> > resolution of relative URLs, as system id serves as a base xml property;
> > while using EntityResolver would be preferrable in cases where I'd like
to
> > introduce some custom io post/pre processing for particular system ids,
> etc.
> > So, my conclusion is that either systemId is ignored (as far as schemas
> > resolution is concerned) by Xerces, and EntityResolver must always be
> used.
> > If systemId is not ignored then either I've not specified it correctly
(in
> > the code I've used many variations:
> > getRealPath("/WEB-INF/devices/config/devices.xml") and
> > getResource("/WEB-INF/devices/config/devices.xml").toString(), with and
> > without devices.xml part in both cases ) or EntityResolve must at least
> > return null to indicate to the a parser that a systemId must be used
> > instead.
> > I'll implement Entity Resolver and it should start validating
> > Thanks
> > Sergey Beryozkin
> >
> > ----- Original Message -----
> > From: "Eddie Robertsson" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, September 19, 2002 12:33 AM
> > Subject: Re: Validating schema file with target namespace?
> >
> >
> > > Hi Siarhei,
> > >
> > > >My question is probably a basic one, but I can't browse the archives
as
> > > >they're currently unavailable.
> > > >I'm using Xerces 2.1.0 from Tomcat  4.1.10 on Windows XP, I've put
the
> > jars
> > > >in %CATALINA_HOME%common/endorced.
> > > >I'd like to validate the following instance:
> > > ><!-- /WEB-INF/devices/fusion/config/devices.xml -->
> > > ><dev:Devices xmlns:dev="http://zandar.com/devices";
> > > >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >     xsi:schemaLocation="http://www.zandar.com/devices devices.xsd">
> > > ><!-- content is not shown -->
> > > ></dev:Devices>
> > > >
> > > >The schema,  /WEB-INF/devices/fusion/config/devices.xsd :
> > > ><xs:schema targetNamespace="http://www.zandar.com/devices";
> > > >                        xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > > >                        xmlns:tns="http://www.zandar.com/devices";>
> > > ><xs:element name="Devices">
> > > ><!-- content is not shown -->
> > > ></xs:element>
> > > ></xs:schema>
> > > >
> > > It seems you have got the namespaces wrong. In the schema the
> > > targetNamespace is "http://www.zandar.com/devices"; but in the instance
> > > document it's "http://zandar.com/devices"; (when declaring the "dev"
> > prefix)
> > >
> > > Cheers,
> > > /Eddie
> > >
> > > >
> > > >Here's the code :
> > > >
> > > >String configPath = "/WEB-INF/devices/fusion/config/devices.xml";
> > > >InputSource configStream = new InputSource(new BufferedInputStream(
> > > >
> > getServletContext().
> > > >
> > > >getResourceAsStream(configPath)));
> > > >
> > >
> >
>
>configStream.setSystemId("file://D:/Tech/Java/J2EE/tomcat4.1.10/webapps/zan
> > d
> > > >ar/WEB-INF/devices/fusion/config/devices.xml");
> > > >
> > > >// I've also tried setting systemId with file:/// (the same as
above),
> > > >getResource (configPath).toString()
> > > >
> > > > SAXParserFactory factory = SAXParserFactory.newInstance();
> > > > SAXParser parser = factory.newSAXParser();
> > > >  XMLReader reader = parser.getXMLReader();
> > > >            try {
> > > >
> reader.setFeature("http://xml.org/sax/features/validation";,
> > > >true);
> > > >
> > > >reader.setFeature("http://apache.org/xml/features/validation/schema";,
> > true);
> > > >            } catch (Exception e) {
> > > >                System.err.println("Cannot activate validation." +
> > > >e.getMessage());
> > > >            }
> > > >
> > > >            ConfigContentHandler handler = new
ConfigContentHandler();
> > > >            reader.setContentHandler(handler);
> > > >            reader.setErrorHandler(handler);
> > > >            reader.parse(configStream);
> > > >
> > > >I get an exception from Xerces that it's unable to locate a
dev:Devices
> > > >element declaration;
> > > >I think my problem with systemId, as I've validated the above
instance
> > with
> > > >XSV.
> > > >
> > > >----- Original Message -----
> > > >From: <[EMAIL PROTECTED]>
> > > >To: <[EMAIL PROTECTED]>
> > > >Sent: Wednesday, September 18, 2002 5:04 PM
> > > >Subject: Re: Validating schema file with target namespace?
> > > >
> > > >
> > > >
> > > >
> > > >>That's strange.
> > > >>
> > > >>The xerces distribution comes with some sample code and sample data.
> > Could
> > > >>you try validating the personal-schema.xml using one of the samples
> > (say,
> > > >>sax.Counter)? After setting the classpath, and switching to the
"data"
> > > >>directory,
> > > >>
> > > >>java sax.Counter -v -s personal-schema.xml
> > > >>
> > > >>If this works, then it should be problem in how you are using the
> > parser.
> > > >>
> > > >>I don't have your original message. I supposed you've set all the
> > > >>
> > > >>
> > > >necessary
> > > >
> > > >
> > > >>features. (validation and validation/schema.) Did you register an
> > > >>EntityResolver? How did you invoke the parser? From the command
line?
> > From
> > > >>which directory? Is the system property "user.dir" set?
> > > >>
> > > >>Thanks,
> > > >>Sandy Gao
> > > >>Software Developer, IBM Canada
> > > >>(1-905) 413-3255
> > > >>[EMAIL PROTECTED]
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>                      "Siarhei
> > > >>                      Biarozkin"               To:
> > > >>
> > > >>
> > > ><[EMAIL PROTECTED]>
> > > >
> > > >
> > > >>                      <[EMAIL PROTECTED]        cc:
> > > >>                      r.com>                   Subject:  Re:
> Validating
> > > >>
> > > >>
> > > >schema file with target namespace?
> > > >
> > > >
> > > >>                      09/18/2002 11:48
> > > >>                      AM
> > > >>                      Please respond to
> > > >>                      xerces-j-user
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>Hello,
> > > >>Thanks for your help !
> > > >>I mistyped the schemaLocation in the email,
> > > >>validation still doesn't work with the following fragment :
> > > >>
> > > >><dev:Devices xmlns:dev="http://zandar.com/devices";
> > > >>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >>    xsi:schemaLocation="http://zandar.com/devices devices.xsd">
> > > >>
> > > >>
> > > >>Cheers
> > > >>Sergey Beryozkin
> > > >>
> > > >>----- Original Message -----
> > > >>From: <[EMAIL PROTECTED]>
> > > >>To: <[EMAIL PROTECTED]>
> > > >>Sent: Wednesday, September 18, 2002 4:32 PM
> > > >>Subject: Re: Validating schema file with target namespace?
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>>><dev:Devices xmlns:dev="http://zandar.com/devices";
> > > >>>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >>>>   xsi:schemaLocation="http://www.zandar.com/devices devices.xsd">
> > > >>>>
> > > >>>>
> > > >>>Should be
> > > >>>
> > > >>><dev:Devices xmlns:dev="http://zandar.com/devices";
> > > >>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >>>   xsi:schemaLocation="http://zandar.com/devices devices.xsd">
> > > >>>
> > > >>>Sandy Gao
> > > >>>Software Developer, IBM Canada
> > > >>>(1-905) 413-3255
> > > >>>[EMAIL PROTECTED]
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>                      "Siarhei
> > > >>>                      Biarozkin"               To:
> > > >>>
> > > >>>
> > > >><[EMAIL PROTECTED]>
> > > >>
> > > >>
> > > >>>                      <[EMAIL PROTECTED]        cc:
> > > >>>                      r.com>                   Subject:  Re:
> Validating
> > > >>>
> > > >>>
> > > >>schema file with target namespace?
> > > >>
> > > >>
> > > >>>                      09/18/2002 04:40
> > > >>>                      AM
> > > >>>                      Please respond to
> > > >>>                      xerces-j-user
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>I have the same problem, where an instance and a schema are located
> in
> > > >>>
> > > >>>
> > > >>the
> > > >>
> > > >>
> > > >>>same directory :
> > > >>><!-- instance doc, should be validated against devices.xsd -->
> > > >>><dev:Devices xmlns:dev="http://zandar.com/devices";
> > > >>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >>>   xsi:schemaLocation="http://www.zandar.com/devices devices.xsd">
> > > >>>
> > > >>>I'd assume though that the problem is with systemId; when I
submitted
> > my
> > > >>>question few days ago I thought I'd get a quick reply...
> > > >>>I guess the only option is to get the source and try to find what's
> > > >>>
> > > >>>
> > > >>really
> > > >>
> > > >>
> > > >>>happening
> > > >>>Cheers
> > > >>>Sergey Beryozkin
> > > >>>----- Original Message -----
> > > >>>From: "Aleksandar Milanovic" <[EMAIL PROTECTED]>
> > > >>>To: <[EMAIL PROTECTED]>
> > > >>>Sent: Wednesday, September 18, 2002 1:05 AM
> > > >>>Subject: RE: Validating schema file with target namespace?
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>>I think your schema location should be:
> > > >>>>
> > > >>>>xsi:schemaLocation="http://mysite.com/Personal/ personal.xsd"
> > > >>>>
> > > >>>>Alex
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>>-----Original Message-----
> > > >>>>>From: Gergely Gati
[mailto:[EMAIL PROTECTED]
> > > >>>>>Sent: Tuesday, September 17, 2002 4:25 PM
> > > >>>>>To: '[EMAIL PROTECTED]'
> > > >>>>>Subject: Validating schema file with target namespace?
> > > >>>>>
> > > >>>>>
> > > >>>>>Hi,
> > > >>>>>
> > > >>>>>I would like to use Xerces for batch XML validation but I
stumbled
> > > >>>>>
> > > >>>>>
> > > >>into
> > > >>
> > > >>
> > > >>>a
> > > >>>
> > > >>>
> > > >>>>>following problem.
> > > >>>>>Xerces does not seem to load the schema file from the same
> directory
> > > >>>>>
> > > >>>>>
> > > >>if
> > > >>
> > > >>
> > > >>>I
> > > >>>
> > > >>>
> > > >>>>>use the
> > > >>>>>targetNamespace stuff in the .xsd file.
> > > >>>>>
> > > >>>>>With xsi:noNamespaceSchemaLocation in the XML file and no
> > > >>>>>targetNamespace in
> > > >>>>>the XSD
> > > >>>>>file it works fine.
> > > >>>>>
> > > >>>>>Could anyone tell me what am I doing wrong?
> > > >>>>>
> > > >>>>>Is there a good example somewhere using Xerces with
targetNamespace
> > > >>>>>
> > > >>>>>
> > > >>in
> > > >>
> > > >>
> > > >>>the
> > > >>>
> > > >>>
> > > >>>>>XSD files?
> > > >>>>>
> > > >>>>>Thanks in advance,
> > > >>>>>Gergely
> > > >>>>>
> > > >>>>>
> > > >>>>>The root element in the XML file starts like this:
> > > >>>>>
> > > >>>>><personnel
> > > >>>>>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >>>>>xmlns="http://mysite.com/Personal/";
> > > >>>>>xsi:schemaLocation=". personal.xsd">
> > > >>>>>
> > > >>>>>The top lines of the .xsd files are:
> > > >>>>>
> > > >>>>><?xml version="1.0" encoding="UTF-8"?>
> > > >>>>><xsd:schema
> > > >>>>>  targetNamespace="http://mysite.com/Personal/";
> > > >>>>>  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> > > >>>>>  xmlns="http://mysite.com/Personal/";
> > > >>>>>  elementFormDefault="qualified"
> > > >>>>>  attributeFormDefault="unqualified">
> > > >>>>>
> > > >>>>>
> > > >>>>>Xerces version 2.1.0
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > >
>>---------------------------------------------------------------------
> > > >>
> > > >>
> > > >>>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>>>>For additional commands, e-mail:
[EMAIL PROTECTED]
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > >
> >>>>---------------------------------------------------------------------
> > > >>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>>>For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > >
>>>---------------------------------------------------------------------
> > > >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>>For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > >
>>>---------------------------------------------------------------------
> > > >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>>For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > >
>>---------------------------------------------------------------------
> > > >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > >
>>---------------------------------------------------------------------
> > > >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >>For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to