Velocity Reviews

Velocity Reviews (
-   Java (
-   -   How to validate XSLT output in java? (

Damon Rand 07-29-2004 05:07 PM

How to validate XSLT output in java?

This should be simple but I am lost in the maze of java xml/xsl
classes. Given a dom Document and an xsl Templates object I want to
run the document through a transformer and validate the output against
a schema and then return the output xml as another Document.

At the moment the only way I can work out how to do this is by
writing the xslt output to a File, then parsing it back in from the
File with validation enabled.. How do I do it directly? Here is where
I have got too. I am working with Java 1.4.2 default implementation.



import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class ValidatingTransform {

public static Document transformXMLDocumentWithValidate(Document
Templates template) throws Exception {

if (in == null)
throw (new Exception("Input document is null"));

// What goes here?
SAXResult result = null;

// Get a transformer from the template
Transformer transformer = template.newTransformer();
transformer.transform(new DOMSource(in), result);

// What goes here??
InputSource source = null;

// Parse the output into a dom with validation
// I am assuming the XSLT output will contain a valid
DocumentBuilderFactory dbFactory =
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document docResult = dBuilder.parse(source);

return docResult;


All times are GMT. The time now is 11:30 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.