You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Per Nyfelt <pe...@nordicwave.com> on 2002/08/16 12:24:15 UTC
problem using setContentAsSAX for large documents
I'm having some problems when inserting large documents using SAX. I choose SAX as I get the content
as a Stream and I'd like to just forward the content to Xindice without loading up a memory
representation of the xml content first. For small documents (<50k) the SAX code works fine but for
larger documents it bombs out. Here's the code I was using:
public static Document setItems(String resourceName, InputStream in) throws InventoryException {
try {
logger.info("Inserting data for resource " + resourceName);
XMLResource resource = (XMLResource) inventory.getResource(resourceName);
if (resource == null) {
logger.debug("creating new resource for " + resourceName);
resource = (XMLResource) inventory.createResource(resourceName, "XMLResource");
}
ContentHandler handler = resource.setContentAsSAX();
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(handler);
reader.setErrorHandler(new StrongErrorHandler());
reader.parse(new InputSource(in));
// This gives an XMLDBException originating from storeResource() in
org.apache.xindice.client.xmldb.embed.CollectionImpl
// The following code works fine instead:
StringBuffer xmlContent = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String temp;
while((temp=reader.readLine()) != null) {
xmlContent.append(temp);
}
resource.setContent(xmlContent.toString());
inventory.storeResource(resource);
.....
}
Looking at CollectionImpl.storeResource() it seems that any store invocation converts the resource
to DOM before calling insertDocument on the collection so this would not explain why converting to
String works fine but using SAX storage does not. Any ideas, suggestions?
Best regards,
Per