xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Leblanc <Se...@e-infodata.com>
Subject Converting DOM to text
Date Mon, 20 Jan 2003 18:04:45 GMT
Hello,
 
I am trying to use the samples to convert DOM I already have in memory to a
string of text.
 
I'm looking at the DOM2DOM sample, and trying to use it, but I get this
error:
 
javax.xml.transform.TransformerException: org.w3c.dom.DOMException:
HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not
permitted.
 
Here is the code. The variable "document" is passed in.
 
// Get ready for a transformation:
        DOMSource xmlDomSource = new DOMSource(document);
        DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();
        dFactory.setNamespaceAware(true);
        DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
        TransformerFactory tFactory = TransformerFactory.newInstance();
        // Get our XSL file, transform into source:
        File xslFile = new File("test.xsl");
        System.out.println("Exists? " + xslFile.exists());
        Document xslDoc = dBuilder.parse(xslFile);
        DOMSource xslDomSource = new DOMSource(xslDoc);
 
        // Set the systemId: note this is actually a URL, not a local
filename
        xslDomSource.setSystemId("");
 
        // Process the stylesheet DOMSource and generate a Transformer.
        Transformer transformer = tFactory.newTransformer(xslDomSource);
 
        // Create an empty DOMResult for the Result.
        DOMResult domResult = new DOMResult();
        
 
                // Perform the transformation, placing the output in the
DOMResult.
        transformer.transform(xmlDomSource, domResult);
 
                //Instantiate an Xalan XML serializer and use it to
serialize the output DOM to System.out
                // using a default output format.
        Serializer serializer = SerializerFactory.getSerializer
 
(OutputProperties.getDefaultMethodProperties("xml"));
        serializer.setOutputStream(System.out);
        serializer.asDOMSerializer().serialize(domResult.getNode());
This e-mail, including attachments, is intended for the person(s) or company
named and may contain confidential and/or legally privileged information.
Unauthorized disclosure, copying or use of this information may be unlawful
and is prohibited. If you are not the intended recipient, please delete this
message and notify the sender.

Mime
View raw message