NGInterface
asked on
Java XSLT transformation problem
Hi,
I am trying to transform a very large XML document using DOM4J in Java. Here's what I do:
1. Read in the original XML file using SAXReader (reader is a SAXReader object):
Document myDoc = reader.read(new File("very_large_xml_file. xml"))...
2. Pass the Document myDoc to the following function that transforms the file:
public Document stylesheet_trans(Document document, String stylesheet)
throws Exception
{
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInst ance();
Transformer transformer = factory.newTransformer(
new StreamSource(stylesheet)
);
// now lets style the given document
DocumentSource source = new DocumentSource(document);
DocumentResult result = new DocumentResult();
transformer.transform(sour ce, result);
// return the transformed document
Document transformedDoc = result.getDocument();
return transformedDoc;
}
finally, write the returned Document to a new file:
final_file = new FileWriter("final_transfor med_large_ xml_file.x ml");
returned_doc.write(final_f ile);
The problem here is, when I opened the final_transformed_large_xm l_file.xml in a browser, it tells me that the document is truncated (that is, the transformation process seems unable to handle such a large original file...) -- there is no real problem with the actual tag transformations, but it is just cut off before the end. Can anyone help me with this problem?
I am trying to transform a very large XML document using DOM4J in Java. Here's what I do:
1. Read in the original XML file using SAXReader (reader is a SAXReader object):
Document myDoc = reader.read(new File("very_large_xml_file.
2. Pass the Document myDoc to the following function that transforms the file:
public Document stylesheet_trans(Document document, String stylesheet)
throws Exception
{
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInst
Transformer transformer = factory.newTransformer(
new StreamSource(stylesheet)
);
// now lets style the given document
DocumentSource source = new DocumentSource(document);
DocumentResult result = new DocumentResult();
transformer.transform(sour
// return the transformed document
Document transformedDoc = result.getDocument();
return transformedDoc;
}
finally, write the returned Document to a new file:
final_file = new FileWriter("final_transfor
returned_doc.write(final_f
The problem here is, when I opened the final_transformed_large_xm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I adjusted the serializer to conform with the DOM4J's API and it now works!
:-)
pleased to help you
it is not recommenden using Document.write() for documents not opened with document.open
see: http://cafeconleche.org/quotes2005.html
and
depending on input maybe sax is not the right approach
http://cafeconleche.org/books/xmljava/chapters/ch06s07.html
use .eg.