aspose file tools*
The moose likes Servlets and the fly likes Exporting a file in Html/XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exporting a file in Html/XML" Watch "Exporting a file in Html/XML" New topic
Author

Exporting a file in Html/XML

sridhar lakka
Ranch Hand

Joined: Jan 02, 2007
Posts: 109
HI,
Thanks in advance.
I need a small help/suggestion for the following.
I have a page which is rendered from JSP.And i can see in a good format what the user has given in previous steps.Now on that page i have buttons to export,if user clicks that button that page out put should export in XML/HTML format.
How to genterate a dynamic XML/HTML in java/jsp.
Please give me some examples.
Thanks a lot
Regrads,
Sreedhar
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Basically you can fllow the steps to do so:
1, Create xml format data you want to export;
2, Create a xsl file(XSLT) to handle the output format, for example html format;
3, Transform the xml data using xsl file to dynamically output the presentation data.

Hope this helps!

Chris
sridhar lakka
Ranch Hand

Joined: Jan 02, 2007
Posts: 109
Hello Chris,
Thanks a lot.
Yes it is help ful for me but could you give me some examples on that.Example code i need.
Please.,
Regards,
Sree
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi,

I was using dom4j. Here is an example how i created Document:
public Document createTestCaseDocument() {
Map symbol_values = AIMT_DB.loadSymbols(planInfo.getCategory());
Document testCaseDocument = DocumentHelper.createDocument();
Element testCaseEle = testCaseDocument.addElement(TEST_CASE_ELE)
.addAttribute(CUSTOMER_ID_ATTR, ""+planInfo.getCustomerID())
.addAttribute(CUSTOMER_NAME_ATTR, planInfo.getCustomerName())
.addAttribute(IVR_ID_ATTR, ""+planInfo.getCategory())
.addAttribute(IVR_NAME_ATTR, planInfo.getCategoryName())
.addAttribute(ID_ATTR, ""+planInfo.getPlanId())
.addAttribute(NAME_ATTR, planInfo.getName())
.addAttribute(AUTHOR_ATTR, planInfo.getAuthor())
.addAttribute(LAST_MODIFIED_ATTR, ""+planInfo.getLastModified())
.addAttribute(IVR_NUMBER_PREFIX_ATTR, planInfo.getIVRNumberPrefix())
.addAttribute(IVR_NUMBER_ATTR, planInfo.getIVRNumber())
.addAttribute(INSTANCES_ATTR, ""+planInfo.getInstances())
.addAttribute(SENSITIVITY_ATTR, ""+planInfo.getSensitivity())
.addAttribute(ALLOWBARGEIN_ATTR, planInfo.isAllowBargein() ? "true" : "false")
.addAttribute(CALLERID_ATTR, planInfo.getCallerID());
//other code here
return testCaseDocument;
}

Use the following functions and xsl file to create my presentation data:
public String outputXML(Document document) {
return document.asXML();
}
public Document styleDocument(
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;
}

Cheers

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exporting a file in Html/XML