Hi all,
I'm trying to parse a large xml-file (~500MB) that contains namespaces.
I tried it the way recommended in the cookbook (see code below) with
a few additional lines to register the namespaces
--->snippet
// register the namespaces
Map uris = new HashMap();
uris.put( "x", "http://www.something.org/dtds/x.dtd#" );
uris.put( "y", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" );
DocumentFactory factory = new DocumentFactory();
factory.setXPathNamespaceURIs( uris );
SAXReader reader = new SAXReader();
reader.setDocumentFactory( factory );
println("Parsing document: " + url);
println("Using Pruning Path: " + pruningPath);
// enable pruning to call me back as each Element is complete
reader.addHandler(pruningPath, this);
println("##### starting parse");
Document document = reader.read(url);
println("##### finished parse");
<----end snippet
The main code to parse the document is from the dom4j FAQ how to handle
very large XML documents except that I added the namespaces
----> start snippet
SAXReader reader = new SAXReader();
reader.addHandler( "/x:ROWSET/y:ROW",
new ElementHandler() {
public void onStart(ElementPath path) {
// do nothing here... }
public void onEnd(ElementPath path) {
// process a ROW element
Element row = path.getCurrent();
Element rowSet = row.getParent();
Document document = row.getDocument();
...
// prune the tree
row.detach();
}
}
);
Document document = reader.read(url);
----end snippet
The XML document looks something like this:
<x:ROWSET xmlns:x="http://www.something.org/x.dtd#"
xmlns:y="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<y:ROW id="1">
...
</y:ROW>
<y:ROW id="2">
...
</y:ROW>
...
<y:ROW id="N">
...
</y:ROW>
</x:ROWSET>
When I run the program the onStart and onEnd methods are not called.
What am I doing wrong?
Any help is greatly appreciated.
Thanks in advance,
Thomas
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user