xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Boag/CAM/Lotus" <Scott_B...@lotus.com>
Subject Re: Problem with org.apache.xalan.xpath.xml.TreeWalker
Date Wed, 26 Jan 2000 15:17:05 GMT
I should also say that the right way to do what you're doing is to use the
Xerces Serializer classes.  FormatterToXML should be considered somewhat
deprecated, and will go away when I am comfortable that the Serializer
classes can match the speed and features of the Xalan FormatterListener


----- Forwarded by Scott Boag/CAM/Lotus on 01/26/00 10:14 AM -----
                    Scott Boag                                                           
                                         To:     Christopher Lambrecht <chrisl@centera.com>
                    01/26/00 10:08       cc:     "Apache XML List (E-mail)" <general@xml.apache.org>,
Brian Dupras 
                    AM                   <briand@centera.com>                      
                                         Subject:     Re: Problem with org.apache.xalan.xpath.xml.TreeWalker
                                         (Document link: Scott Boag)                     

Christopher, the problem is actually in TreeWalker, but in the
FormatterToXML class.  It keeps an internal buffer that is not being
flushed unless endDocument is called.  You can work around this by doing:

public static String nodeToString(Node node) throws SAXException{
    StringWriter sw = new StringWriter();
    FormatterToXML fl = new FormatterToXML(sw);
    if(node.getNodeType() != Node.DOCUMENT_NODE)
        m_shouldNotWriteXMLHeader = true;  // since it's not a document?
    TreeWalker tw = new TreeWalker(fl);
    if(node.getNodeType() != Node.DOCUMENT_NODE)
    return sw.toString();

The only change I'm going to make to the code for this is to make
FormatterToXML.flush() public.


                    Lambrecht            To:     "Apache XML List (E-mail)" <general@xml.apache.org>
                    <chrisl@cente        cc:     Brian Dupras <briand@centera.com>,
(bcc: Scott Boag/CAM/Lotus)    
                    ra.com>              Subject:     Problem with org.apache.xalan.xpath.xml.TreeWalker
                    05:39 PM                                                             
                    respond to                                                           

I'm using Xalan 0_19_2, Xerces 1_0_0, & JDK 1.2.2 and I've run into a
problem using the TreeWalker to convert a org.w3c.dom.Node object into XML.
If I feed the TreeWalker a Document, it creates the string representation
just fine.  If I feed the TreeWalker a Node, I don't get anything back.
I've included a sample that illustrates the problem.

Christopher Lambrecht

View raw message