Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] xpointer

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Greg Saunders" <saundersgreg AT hotmail.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] xpointer
  • Date: Mon, 06 Dec 2004 10:43:11 -0500

Hi,

I have noticed in the XOM tutorial that "XOM supports the April 13, 2004 Candidate Recommendation of XInclude including the XPointer element() scheme and bare name XPointers, but not the XPointer xpointer() scheme." [1]

I have been able to include an element of one document in another using the element() scheme, but, understanding "bare name XPointers" as the values of id attributes, I don't don't then understand why I get the following error message . . .

nu.xom.xinclude.XIncludeException: XPointer foo did not locate any nodes in the document http://my.example.org/translation-en.xml

. . . from the following (including) XML instance document - note "xpointer" attribute of the "xi:include" element . . .

<?xml version="1.0" encoding="UTF-8"?>

<cc:item
xmlns:cc="http://my.example.org/";
xmlns:xml="http://www.w3.org/XML/1998/namespace";
xmlns:xi="http://www.w3.org/2001/XInclude";
>

<xi:include
href="my.example.org/translation-en.xml"
xpointer="foo"
/>

<somethingelse>Hello</somethingelse>

</cc:item>

. . . (included) XML instance document - not "id" attribute of the root "translation" element . . .

<?xml version="1.0" encoding="UTF-8"?>

<cc:translation
xmlns:cc="http://my.example.org/";
xmlns:xml="http://www.w3.org/XML/1998/namespace";
xml:lang="en"
original="true"
id="foo"
>

<h>This is a heading</h>
<p>This is a paragraph that belongs to the heading</p>
<p>This is another paragraph belonging to the same heading</p>

</cc:translation>

Not fully understanding what is meant by "schema-determined" in the XPointer Framework recommendation [2], I have just-in-case ensured that the translation element's id attribute is defined as being of the XML Schema "ID" type, in the schema below - if that has any bearing.

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xml="http://www.w3.org/XML/1998/namespace";
xmlns="http://my.example.org/";
targetNamespace="http://my.example.org/";
>

<xsd:import
namespace="http://www.w3.org/XML/1998/namespace";
schemaLocation="http://www.w3.org/2001/03/xml.xsd";
/>

<xsd:element name="translation" type="TranslationType"/>

<xsd:complexType name="TranslationType">
<xsd:sequence>
<xsd:element name="h" type="xsd:string"/>
<xsd:element name="p" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute ref="xml:lang" use="required"/>
<xsd:attribute name="id" type="xsd:ID" use="required"/>
<xsd:attribute name="original" type="xsd:boolean" use="required"/>
</xsd:complexType>

</xsd:schema>

My Java class looks like this:

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Serializer;
import nu.xom.xinclude.XIncluder;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class MyClass {

public static void main(String args[]) {

try {

XMLReader xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

xerces.setFeature("http://xml.org/sax/features/validation";, true);
xerces.setFeature("http://apache.org/xml/features/validation/schema";, true);
xerces.setFeature("http://apache.org/xml/features/validation/schema-full-checking";, true);
xerces.setFeature("http://apache.org/xml/features/standard-uri-conformant";, true);

xerces.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation";,
"http://my.example.org/ http://my.example.org/translation.xsd";);
xerces.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation";,
"http://my.example.org/ http://my.example.org/item.xsd";);

Builder parser = new Builder(xerces, true);

Document input = parser.build("http://my.example.org/item.xml";);
Document reslt = XIncluder.resolve(input);

Serializer serializer = new Serializer(System.out, "UTF-8");
serializer.setIndent(4);
serializer.setMaxLength(80);
serializer.setPreserveBaseURI(false);
serializer.write(reslt);

System.out.println("Done and done.");

}
catch (Exception e) {
System.out.println(e);
}

}

}

I am using . . .

java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b04)
Java HotSpot(TM) Client VM (build 1.4.2_04-b04, mixed mode)

. . . and running my class with the following command:

/opt/SUNWappserver/jdk/bin/java -classpath /usr/local/xerces-2_6_2/xercesImpl.jar:/path/to/where/I/have/xom-1.0b7.jar:. MyClass

Am I not correctly referencing the id attribute's value in the xpointer attribute of the xi:include element?

Thanks in advance,

Greg.

[1] http://www.cafeconleche.org/XOM/tutorial.xhtml#d0e1864
[2] http://www.w3.org/TR/2003/REC-xptr-framework-20030325/#shorthand






Archive powered by MHonArc 2.6.24.

Top of Page