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]