paul.band...@nomura.com wrote:
Hi,
I have recently started using Xalan/Xerces to help with , very much
using the sample code to guide what I'm doing. I've successfully parsed
and transformed one document into a XalanSourceTreeDocument for
programmatic access, now am trying to programmatically construct an XML
document then transform it, patterning my code after the
'DocumentBuilder' sample. However, although the document construction
and transform appear to execute without error, the resulting document
hasn't been populated with attribute values from the constructed
document.
This is usually because of namespace issues with the attributes.
I would very much like to be able to 'dump' out the contents of the
programmatically constructed document built using XalanDocumentBuilder
and its ContentHandler. Is there a way to get it streamed out say to
cerr without having to passing it thru' the transformer?
Take a look at the SerializeNodeSet sample application, which uses a
serializer and a tree walker to do this. The basic code will look
something like this:
XalanStdOutputStream theStream(std::cerr);
XalanOutputStreamPrintWriter thePrintWriter(theStream);
FormatterToXML theFormatter(thePrintWriter);
FormatterTreeWalker theWalker(theFormatter);
theWalker.traverse(doc);
BTW, I noticed some discussion on the April archive from someone who was
programmatically constructing a document and then transforming it, but
they appeared to be using different classes as their code referred to
constructing 'DOMDocument' directly so I'm a bit unsure whether using
XalanDocumentBuilder is the right approach? In that discussion the
poster was referred to caution needed in establishing attribute
name-spaces, but I don't see anything like that in the provided
DocumentBuilder sample code...?
Those are Xerces-C DOM classes, and I would not recommend using them
unless you need to manipulate a DOM or construct one in such a way that
can't be done using the SAX2-based approach of XalanDocumentBuilder.
Dave