Here is how to format XMLDOM output nicely

Gave me a hard time, so I thought I would share. If you don’t do this, everything will be in one line…

//Name DataType Subtype Length
//Outs OutStream
//F File
//Reader Automation ‘Microsoft XML, v6.0’.SAXXMLReader60
//Writer Automation ‘Microsoft XML, v6.0’.MXXMLWriter60

F.QUERYREPLACE(FALSE);
F.CREATE(FileName);
F.CREATEOUTSTREAM(Outs);

IF ISCLEAR(Writer) THEN
CREATE(Writer);

Writer.indent := TRUE;
Writer.standalone := FALSE;
Writer.omitXMLDeclaration := TRUE;
Writer.encoding := ‘utf-8’;

IF ISCLEAR(Reader) THEN
CREATE(Reader);

Reader.contentHandler := Writer;
Reader.dtdHandler := Writer;
Reader.errorHandler := Writer;

Reader.putProperty(‘http://xml.org/sax/properties/declaration-handler’, Writer);
Reader.putProperty(‘http://xml.org/sax/properties/lexical-handler’, Writer);

Reader.parse(PXMLDocOut);

PXMLDocOut.loadXML(Writer.output);

PXMLDocOut.save(Outs);
F.CLOSE;

Bron : Miklos Hollender

Leave a Comment.