?
Solved

Java XSLT transformation problem

Posted on 2006-03-25
6
Medium Priority
?
413 Views
Last Modified: 2013-11-23
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.newInstance();
        Transformer transformer = factory.newTransformer(
            new StreamSource(stylesheet)
        );

        // now lets style the given document
        DocumentSource source = new DocumentSource(document);
        DocumentResult result = new DocumentResult();
        transformer.transform(source, 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_transformed_large_xml_file.xml");
returned_doc.write(final_file);

The problem here is, when I opened the final_transformed_large_xml_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?
0
Comment
Question by:NGInterface
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:mightyone
ID: 16290282
try using your own serialisation...

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.
0
 
LVL 6

Accepted Solution

by:
mightyone earned 1800 total points
ID: 16290300
// Serialize the document
      OutputFormat format = new OutputFormat(doc);
      format.setLineWidth(65);
      format.setIndenting(true);
      format.setIndent(2);
      XMLSerializer serializer = new XMLSerializer(System.out, format);
      serializer.serialize(doc);
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 16290585
>>the transformation process seems unable to handle such a large original file

That seems unlikely. More likely, perhaps, is that the browser can't handle it.

Assuming Windows, issue the command:

type yourfile.xml

and look for the closing tag

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:NGInterface
ID: 16290909
Thanks. I adjusted the serializer to conform with the DOM4J's API and it now works!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16293054
:-)
0
 
LVL 6

Expert Comment

by:mightyone
ID: 16294238
pleased to help you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question