Hi Gerrard,
Gerrard Drury <[EMAIL PROTECTED]> wrote on 07/14/2005 04:27:17 AM:
> Hi Michael,
>
> Thanks for your response and explanation. I guess this logically leads
> to the next set of questions.
>
> 1. Is Xerces likely to consider adding support for this in the future?
We kicked around a few possibilities but none seemed workable. The problem
is that the schema validation feature is a boolean (either validation is
on or off), but the user might want to validate before XInclude or after
XInclude or both or only some of the source infosets or possibly some of
the partial results. These combinations cannot simply be described by a
feature you turn on or off. It gets even more complicated if in the future
Xerces supports another spec whose processing could logically occur before
or after schema validation (as well as before or after XInclude
processing).
> 2. Do you have any advice for a workaround?
At the moment only DTD-determined IDs are supported, so you could provide
a DTD which declares which attributes are of type ID.
>
> While investigating this further, I also might have come across a
> possible bug.
>
> Package: org.apache.xerces.xpointer
> Class: ShorthandPointer
> Method: getSchemaDeterminedID(XMLAttributes, int)
>
> This includes the code:
>
> XSTypeDefinition typeDef = attrPSVI.getMemberTypeDefinition();
> if (typeDef != null) {
> typeDef = attrPSVI.getTypeDefinition();
> }
>
> Whereas I think possibly it should be "if (typeDef == null)"?
You're right. It should be checking if it's equal to null.
>
> Also, if it is of interest, I have made some hacks which results in the
> xpointer being resolved as I would expect. However, not being familiar
> with the details of Xerces implementation, I suspect what I have done is
> at the least not very efficient (I am guessing one of the reasons the
> decision was made not to do any validation except on the final result),
> and maybe even having unforseen side-effects.
>
> Here's a list of the hacks.
>
> 1. In XIncludeHandler.reset(), comment out the lines that are setting
> the validation related features to false.
This would cause a schema validator to be on every one of the child
pipelines meaning in addition to the final result, all the partial results
at each include depth would be validated. Besides the performance issue
this introduces, your schema may not describe all of these infosets so you
could see many errors reported particularly for elements which will
eventually be filtered out by an XPointer at a higher include depth.
> 2. In XPointerParserConfiguration.configurePipeline(), comment out the
> insertion of the fXIncludeHandler before the fSchemaValidator.
I don't know this portion of the code but this seems to remove XInclude
processing from the XPointer pipeline meaning any nested includes wouldn't
be processed correctly.
> 3. Above mentioned change to ShorthandPointer.getSchemaDeterminedID().
>
> Patches follow.
>
> --- XIncludeHandler.java Sat Jun 25 06:21:42 2005
> +++ XIncludeHandler-New.java Thu Jul 14 08:01:48 2005
> @@ -553,6 +553,7 @@
> // we don't want a schema validator on the new pipeline,
> // so if it was enabled, we set the feature to false as
> // well as other validation features.
> +/*
> try {
> if (componentManager.getFeature(SCHEMA_VALIDATION)) {
> fSettings.setFeature(SCHEMA_VALIDATION, false);
> @@ -561,6 +562,7 @@
> }
> }
> catch (XMLConfigurationException e) {}
> +*/
>
> // Don't reset fChildConfig -- we don't want it to share the
> same components.
> // It will be reset when it is actually used to parse
something.
>
>
> --- XPointerParserConfiguration.java Sat Jun 25 06:21:42 2005
> +++ XPointerParserConfiguration-New.java Thu Jul 14 08:04:52 2005
> @@ -158,6 +158,7 @@
> // configure XML document pipeline: insert after DTDValidator
and
> // before XML Schema validator
> XMLDocumentSource prev = null;
> + /*
> if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
> // we don't have to worry about fSchemaValidator being
> null, since
> // super.configurePipeline() instantiated it if the
> feature was set
> @@ -165,6 +166,7 @@
> }
> // Otherwise, insert after the last component in the pipeline
> else {
> + */{
> prev = fLastComponent;
> fLastComponent = fXPointerHandler;
> }
>
>
> --- ShortHandPointer.java Sat Jun 25 06:21:42 2005
> +++ ShortHandPointer-New.java Thu Jul 14 07:38:41 2005
> @@ -217,7 +217,7 @@
> // the [base type definition] property recursively;
>
> XSTypeDefinition typeDef =
attrPSVI.getMemberTypeDefinition();
> - if (typeDef != null) {
> + if (typeDef == null) {
> typeDef = attrPSVI.getTypeDefinition();
> }
>
>
> Michael Glavassevich wrote:
> > Hi Gerrard,
> >
> > The reason this isn't working for you is that in Xerces, schema
validation
> > is performed on the result infoset produced by the XInclude processor.
> > (XInclude does not specify a processing order, so this was an
> > implementation decision.) When the XPointer is processed it isn't
known
> > that the type of the attribute will eventually be determined to be an
ID
> > so it doesn't recognize it as one. I don't think this is mentioned
> > anywhere in the docs so I intend to add an FAQ to the website. In
order
> > for the schema determined IDs to be available to the XInclude
processor,
> > each of the source infosets would need to be validated before being
passed
> > into the XInclude processor. This currently isn't supported.
> >
> > Thanks.
> >
> > Gerrard Drury <[EMAIL PROTECTED]> wrote on 07/13/2005 07:55:18
AM:
> >
> >
> >>Hi,
> >>
> >>I am getting an "XPointer resolution unsuccessful" error when I have
an
> >>XInclude include element that has an xpointer attribute using the
> >>XPointer element() Scheme and that begins with an NCName (i.e. a
> >>shorthand pointer).
> >>
> >>The include element I am using looks like:
> >>
> >><xi:include href="includeSource.xml" xpointer="element(id1/1)"/>
> >>
> >>The error message when I attempt to parse the input source containing
> >>this include element is:
> >>
> >>WARNING: org.xml.sax.SAXParseException: Include operation failed,
> >>reverting to fallback. Resource error reading file as XML
> >>(href='includeSource.xml'). Reason: XPointer resolution unsuccessful.
> >>
> >>The include then fails, since I do not specify a fallback.
> >>
> >>I am not sure if it is a configuration error on my part, or possibly a
> >>problem in Xerces-J.
> >>
> >>I have a valid schema specifying the ID attributes in both the input
> >>source and include source, and have set the parser to be validating.
> >>
> >>If I parse the include source using the schema it validates ok.
> >>
> >>The problem is when I try to include it using the above XInclude
include
> >
> >
> >>element in the input source document.
> >>
> >>If I change the xpointer so that it uses only a child sequence, then
the
> >
> >
> >>include works fine:
> >>
> >><xi:include href="includeSource.xml" xpointer="element(/1/1/1/1)"/>
> >>
> >>I am using Xerces-J v2.7.0 and J2SE 1.5.0 (with Eclipse 3.0.1 as my
> >
> > IDE).
> >
> >>I did a bit of digging around with the Eclipse debugger, and what I
have
> >
> >
> >>noticed is that when ShorthandPointer.hasMatchingIdentifier() is
called,
> >>it seems that when the include source is parsed, it is not picking up
> >>the attribute I specify as being of type ID in my schema.
> >>
> >>A complete set of sample files that demonstrates the problem is given
> >
> > below.
> >
> >>Any advice would be appreciated.
> >>
> >>Thanks,
> >>Gerrard
> >>
> >>------- foo.xsd -------
> >><schema targetNamespace="http://foo.bar.com"
> >>xmlns="http://www.w3.org/2001/XMLSchema"
> >> xmlns:foo="http://foo.bar.com" elementFormDefault="qualified"
> >>attributeFormDefault="unqualified">
> >> <element name="root">
> >> <complexType>
> >> <sequence>
> >> <element name="element1">
> >> <complexType>
> >> <sequence>
> >> <element name="element2">
> >> <complexType>
> >> <sequence>
> >> <element name="element3"
> >>type="string"/>
> >> </sequence>
> >> <attribute name="id" type="ID"/>
> >> </complexType>
> >> </element>
> >> </sequence>
> >> <attribute name="idref" type="IDREFS"/>
> >> </complexType>
> >> </element>
> >> </sequence>
> >> </complexType>
> >> </element>
> >></schema>
> >>------- end of foo.xsd --
> >>
> >>------- includeSource.xml -------
> >><root xmlns="http://foo.bar.com"
> >>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >> xsi:schemaLocation="http://foo.bar.com foo.xsd">
> >> <element1 idref="id1">
> >> <element2 id="id1">
> >> <element3>Some text</element3>
> >> </element2>
> >> </element1>
> >></root>
> >>------- end of includeSource --
> >>
> >>------- inputSource.xml -------
> >><root xmlns="http://foo.bar.com"
> >>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >> xmlns:xi="http://www.w3.org/2001/XInclude"
> >>xsi:schemaLocation="http://foo.bar.com foo.xsd">
> >> <element1>
> >> <element2>
> >> <xi:include href="includeSource.xml"
> >>xpointer="element(id1/1)"/>
> >> </element2>
> >> </element1>
> >></root>
> >>------- end of inputSource.xml --
> >>
> >>------- ParseTest.java -------
> >>import java.io.File;
> >>
> >>import javax.xml.parsers.DocumentBuilder;
> >>import javax.xml.parsers.DocumentBuilderFactory;
> >>
> >>import org.apache.xerces.impl.Version;
> >>import org.apache.xml.serialize.XMLSerializer;
> >>import org.w3c.dom.Document;
> >>import org.xml.sax.ErrorHandler;
> >>import org.xml.sax.SAXException;
> >>import org.xml.sax.SAXParseException;
> >>
> >>public class ParserTest {
> >>
> >> private static File inputSource = new File("inputSource.xml");
> >> private static File includeSource = new
> >
> > File("includeSource.xml");
> >
> >> private static MyErrorHandler errorHandler = new
MyErrorHandler();
> >>
> >> public static void main(String[] args) {
> >> System.out.println(Version.getVersion());
> >> parseFile(includeSource);
> >> parseFile(inputSource);
> >> }
> >>
> >> private static void parseFile(File file) {
> >> System.out.println("--------------------------------");
> >> System.out.println("File: " + file.getAbsolutePath());
> >> try {
> >> DocumentBuilderFactory factory =
> >> DocumentBuilderFactory.newInstance();
> >> System.out.println("Factory: " +
> >
> > factory.getClass().getName());
> >
> >> factory.setNamespaceAware(true);
> >> factory.setValidating(true);
> >> factory.setXIncludeAware(true);
> >> factory.setAttribute(
> >> "http://apache.org/xml/features/validation/schema",
> >> Boolean.TRUE);
> >> factory.setAttribute(
> >>"http://apache.org/xml/features/xinclude/fixup-base-uris",
> >> Boolean.FALSE);
> >> factory.setAttribute(
> >> "http://apache.org/xml/features/xinclude/fixup-language
",
> >> Boolean.FALSE);
> >>
> >> DocumentBuilder builder = factory.newDocumentBuilder();
> >> System.out.println("Builder: " +
> >
> > builder.getClass().getName());
> >
> >> builder.setErrorHandler(errorHandler);
> >>
> >> Document document = builder.parse(file);
> >> System.out.println("Document: " +
> >>document.getClass().getName());
> >>
> >> XMLSerializer serializer = new XMLSerializer();
> >> System.out.println("Serializer: " +
> >>serializer.getClass().getName());
> >> serializer.setOutputByteStream(System.out);
> >> serializer.serialize(document);
> >>
> >> System.out.println();
> >> }
> >> catch(Exception e) {
> >> System.err.println(e);
> >> }
> >> }
> >>
> >> private static class MyErrorHandler implements ErrorHandler {
> >> public void warning(SAXParseException exception)
> >> throws SAXException {
> >> System.err.println("WARNING: " + exception);
> >> }
> >> public void error(SAXParseException exception)
> >> throws SAXException {
> >> System.err.println("ERROR: " + exception);
> >> }
> >> public void fatalError(SAXParseException exception)
> >> throws SAXException {
> >> System.err.println("FATAL: " + exception);
> >> }
> >> }
> >>}
> >>------- end of ParseTest.java --
>
> --
> Gerrard Drury
> Software Engineer
> Telecommunications & Information Technology Research Institute
> Rm104 Bld4, University of Wollongong, Wollongong NSW 2522, Australia
> mailto:[EMAIL PROTECTED] http://www.titr.uow.edu.au
> ph:+61-2-42215314 fx:+61-2-42273277
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]