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 Tim Carpenter <ti...@yahoo.co.uk> on 2007/02/09 03:50:34 UTC
Update...deeper:Schema for Validation picked up on one machine, not another
Update:
I have managed to beat the system into finding my xsd file by using
the following:
urlStr = new String("my-schema.xsd"); // file is local to the
APPLICATION not to the source files.
File xmlFile = new File(urlStr);
FileReader xmlfr = new FileReader(xmlFile);
InputSource inputSource = new InputSource(xmlfr);
parser.parse(inputSource);
Unfortunately, my schema, that begins with:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
throws out the following when validating...
SEVERE: cvc-elt.1: Cannot find the declaration of element
'xs:schema'. at line number 2
Now, this works fine on another machine. The erroneous machine is
being accessed via FTP over the net, so it is a net-visible unit. It
appears not to be able to accurately locate the w3 definition...most
odd.
Any ideas on this or improvements to how I am getting access to my
schema?
Tim
___________________________________________________________
All New Yahoo! Mail � Tired of Vi@gr@! come-ons? Let our SpamGuard protect you. http://uk.docs.yahoo.com/nowyoucan.html
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Update...deeper:Schema for Validation picked up on one machine, not
another
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Tim,
Using the Endorsed Standards Override Mechanism is essential if you want
to make use of JAXP 1.3 on JDK 1.4.2. If you merely put the jars on the
classpath you can end up with a hybrid mess where some of the API and
implementation get loaded from the JDK and other parts get loaded from the
jars.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Tim Carpenter <ti...@yahoo.co.uk> wrote on 02/14/2007 04:12:58 AM:
> Thanks for replying, Michael,
>
> That's what the error looks like, for sure, but this error only
> occurs on one machine, the other (devt) machine validates the
> document correctly against the schema. I know for sure, as it throws
> out about 4 errors (and rightly so) in regard to element data content
> in the xml document. Same JAR on one machine as the other.
>
> I have been trying various methods, even using the following:
>
> System.setProperty
> ("javax.xml.parsers.DocumentBuilderFactory",
> "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
>
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> factory.setNamespaceAware(true);
> factory.setValidating(true);
> factory.setAttribute("http://java.sun.com/xml/jaxp/properties/
> schemaLanguage", "http://www.w3.org/2001/XMLSchema" );
> factory.setAttribute("http://java.sun.com/xml/jaxp/properties/
> schemaSource", "file:my_schema.xsd");
>
> DocumentBuilder builder =factory.newDocumentBuilder();
>
> MySAXErrorHandler handler = new MySAXErrorHandler(log);
> builder.setErrorHandler(handler);
> builder.parse(XmlDocumentUrl);
>
> The above again works on one, but chokes on another. This gave that
> very irritating error message saying it was one of three errors (this
> might benefit from some refinement).
>
> I have just tried the following:
>
> String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
> SchemaFactory factory = SchemaFactory.newInstance(language);
> handler = new MySAXErrorHandler(log);
>
> factory.setErrorHandler(handler);
> StreamSource ss = new StreamSource(new File(xmlSchema));
> schema = factory.newSchema(ss);
> validator = schema.newValidator();
> validator.setErrorHandler(handler);
> validator.validate(new StreamSource(XmlDocumentUrl));
>
> which runs on one but throws out an error saying that the W3C string
> is a bad parameter as soon as I instantiate the factory on the other.
> This has set me experimenting with endorsed directories, which might
> be why the destination system, running 1.4.2 is having issues due to
> V1.3 JAXP libraries in my "Fat JAR" being ignored over those in the
> JVM. I think this is the solution, frankly. Note my development
> machine is also running 1.4.2.
>
> That said, in each case it is a very vague error to issue if there is
> a library shortfall ! The last code fragment has enabled me to move
> forward purely because an exception is thrown right at the moment I
> instantiate the factory and so set me on the "endorsed directory"
> trail and away from the goose chase of URIs.
>
> In one way unfair to criticise the library if this problem is due to
> my JAR arrangement (lack of endorsed directory setting) but on the
> other hand, the xerces library really should throw an exception if I
> am trying to set a property (e.g. schema location) that is not yet
> supported. What happens is it is in an unpredicatble state and then
> throws out very misleading errors. If the exception was thrown
> earlier, then it would have been more helpful. Again, this may well
> be due to the unfortunate hybrid JAR arrangement that existed, but if
> not, it might be worth visiting to ensure that things are thrown when
> they should be.
>
> At least if someone else has this problem on 1.4.2, I would suggest
> they resolve the endorsed directories before progressing.
>
> UPDATE: Endorsed directories do seem to resolve it. I am using the
> last fragment (compiling the schema and using a validator) as I often
> need to parse multiple documents of the same schema in quick succession.
>
> NOTE: I just want to say, this issue aside, all the libraries I have
> used in this area - xerces, xpath and the jaxp are a pleasure to use
> in terms of how they are accessed, structured and most importantly to
> me, named. Very professional, IMHO.
>
> Tim
>
>
> On 14 Feb 2007, at 05:33, Michael Glavassevich wrote:
>
> > Hi Tim,
> >
> > Tim Carpenter <ti...@yahoo.co.uk> wrote on 02/08/2007 09:50:34
> > PM:
> >
> >> Update:
> >>
> >> I have managed to beat the system into finding my xsd file by using
> >> the following:
> >>
> >> urlStr = new String("my-schema.xsd"); // file is local to the
> >> APPLICATION not to the source files.
> >> File xmlFile = new File(urlStr);
> >> FileReader xmlfr = new FileReader(xmlFile);
> >> InputSource inputSource = new InputSource(xmlfr);
> >> parser.parse(inputSource);
> >>
> >> Unfortunately, my schema, that begins with:
> >>
> >> <?xml version="1.0" encoding="ISO-8859-1" ?>
> >> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >> elementFormDefault="qualified">
> >>
> >> throws out the following when validating...
> >>
> >> SEVERE: cvc-elt.1: Cannot find the declaration of element
> >> 'xs:schema'. at line number 2
> >>
> >> Now, this works fine on another machine. The erroneous machine is
> >> being accessed via FTP over the net, so it is a net-visible unit. It
> >> appears not to be able to accurately locate the w3 definition...most
> >> odd.
> >>
> >> Any ideas on this or improvements to how I am getting access to my
> >> schema?
> >
> > Given the error message, it looks like you're trying to validate your
> > schema document instead of the instance document. Is that what you
> > really
> > intended to do?
> >
> >> Tim
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> >> For additional commands, e-mail: j-users-help@xerces.apache.org
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
> >
>
>
>
> ___________________________________________________________
> Inbox full of spam? Get leading spam protection and 1GB storage with
> All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
>
> ---------------------------------------------------------------------
> 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: Update...deeper:Schema for Validation picked up on one machine, not another
Posted by Tim Carpenter <ti...@yahoo.co.uk>.
Thanks for replying, Michael,
That's what the error looks like, for sure, but this error only
occurs on one machine, the other (devt) machine validates the
document correctly against the schema. I know for sure, as it throws
out about 4 errors (and rightly so) in regard to element data content
in the xml document. Same JAR on one machine as the other.
I have been trying various methods, even using the following:
System.setProperty
("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/
schemaLanguage", "http://www.w3.org/2001/XMLSchema" );
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/
schemaSource", "file:my_schema.xsd");
DocumentBuilder builder =factory.newDocumentBuilder();
MySAXErrorHandler handler = new MySAXErrorHandler(log);
builder.setErrorHandler(handler);
builder.parse(XmlDocumentUrl);
The above again works on one, but chokes on another. This gave that
very irritating error message saying it was one of three errors (this
might benefit from some refinement).
I have just tried the following:
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
SchemaFactory factory = SchemaFactory.newInstance(language);
handler = new MySAXErrorHandler(log);
factory.setErrorHandler(handler);
StreamSource ss = new StreamSource(new File(xmlSchema));
schema = factory.newSchema(ss);
validator = schema.newValidator();
validator.setErrorHandler(handler);
validator.validate(new StreamSource(XmlDocumentUrl));
which runs on one but throws out an error saying that the W3C string
is a bad parameter as soon as I instantiate the factory on the other.
This has set me experimenting with endorsed directories, which might
be why the destination system, running 1.4.2 is having issues due to
V1.3 JAXP libraries in my "Fat JAR" being ignored over those in the
JVM. I think this is the solution, frankly. Note my development
machine is also running 1.4.2.
That said, in each case it is a very vague error to issue if there is
a library shortfall ! The last code fragment has enabled me to move
forward purely because an exception is thrown right at the moment I
instantiate the factory and so set me on the "endorsed directory"
trail and away from the goose chase of URIs.
In one way unfair to criticise the library if this problem is due to
my JAR arrangement (lack of endorsed directory setting) but on the
other hand, the xerces library really should throw an exception if I
am trying to set a property (e.g. schema location) that is not yet
supported. What happens is it is in an unpredicatble state and then
throws out very misleading errors. If the exception was thrown
earlier, then it would have been more helpful. Again, this may well
be due to the unfortunate hybrid JAR arrangement that existed, but if
not, it might be worth visiting to ensure that things are thrown when
they should be.
At least if someone else has this problem on 1.4.2, I would suggest
they resolve the endorsed directories before progressing.
UPDATE: Endorsed directories do seem to resolve it. I am using the
last fragment (compiling the schema and using a validator) as I often
need to parse multiple documents of the same schema in quick succession.
NOTE: I just want to say, this issue aside, all the libraries I have
used in this area - xerces, xpath and the jaxp are a pleasure to use
in terms of how they are accessed, structured and most importantly to
me, named. Very professional, IMHO.
Tim
On 14 Feb 2007, at 05:33, Michael Glavassevich wrote:
> Hi Tim,
>
> Tim Carpenter <ti...@yahoo.co.uk> wrote on 02/08/2007 09:50:34
> PM:
>
>> Update:
>>
>> I have managed to beat the system into finding my xsd file by using
>> the following:
>>
>> urlStr = new String("my-schema.xsd"); // file is local to the
>> APPLICATION not to the source files.
>> File xmlFile = new File(urlStr);
>> FileReader xmlfr = new FileReader(xmlFile);
>> InputSource inputSource = new InputSource(xmlfr);
>> parser.parse(inputSource);
>>
>> Unfortunately, my schema, that begins with:
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified">
>>
>> throws out the following when validating...
>>
>> SEVERE: cvc-elt.1: Cannot find the declaration of element
>> 'xs:schema'. at line number 2
>>
>> Now, this works fine on another machine. The erroneous machine is
>> being accessed via FTP over the net, so it is a net-visible unit. It
>> appears not to be able to accurately locate the w3 definition...most
>> odd.
>>
>> Any ideas on this or improvements to how I am getting access to my
>> schema?
>
> Given the error message, it looks like you're trying to validate your
> schema document instead of the instance document. Is that what you
> really
> intended to do?
>
>> Tim
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
>> For additional commands, e-mail: j-users-help@xerces.apache.org
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
___________________________________________________________
Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: Update...deeper:Schema for Validation picked up on one machine, not
another
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Tim,
Tim Carpenter <ti...@yahoo.co.uk> wrote on 02/08/2007 09:50:34 PM:
> Update:
>
> I have managed to beat the system into finding my xsd file by using
> the following:
>
> urlStr = new String("my-schema.xsd"); // file is local to the
> APPLICATION not to the source files.
> File xmlFile = new File(urlStr);
> FileReader xmlfr = new FileReader(xmlFile);
> InputSource inputSource = new InputSource(xmlfr);
> parser.parse(inputSource);
>
> Unfortunately, my schema, that begins with:
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
> throws out the following when validating...
>
> SEVERE: cvc-elt.1: Cannot find the declaration of element
> 'xs:schema'. at line number 2
>
> Now, this works fine on another machine. The erroneous machine is
> being accessed via FTP over the net, so it is a net-visible unit. It
> appears not to be able to accurately locate the w3 definition...most
> odd.
>
> Any ideas on this or improvements to how I am getting access to my
> schema?
Given the error message, it looks like you're trying to validate your
schema document instead of the instance document. Is that what you really
intended to do?
> Tim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org