You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Isaac S." <is...@netvision.net.il> on 2001/12/13 21:30:49 UTC

Using JAXP for DOM -> String transformation

Hi there.

I'm using JAXP in order to extract the String representation of a DOM document:

*********************************

Document        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
StringWriter    sw = new StringWriter();

Transformer t = TransformerFactory.newInstance().newTransformer();

DOMSource    src    = new DOMSource(doc);
StreamResult target = new StreamResult(sw);

t.transform(src,target);

*********************************

Now 'target.toString()' will give me the String representation of the DOM document.
The problem is, that I need this string *without* the standard header ("<?xml version....").

How can I do that using JAXP & DOM API's only?


Thanks.


    - Isaac

RE: Using JAXP for DOM -> String transformation

Posted by Paul Brown <pr...@fivesight.com>.
> [[HTML email with JAXP question]]

Even though you send HTML email (tsk tsk tsk), I'll help you out:

t.setOutputProperties(OutputKeys.OMIT_XML_DECLARATION,new Boolean(true));

will leave the declaration off.

    -- Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org