* @param receiver the output handler
*/
private void writeXML( DocumentImpl doc, Receiver receiver )
{
try {
EmbeddedXMLStreamReader reader;
char[] ch;
int nsdecls;
final NamespaceSupport nsSupport = new NamespaceSupport();
final NodeList children = doc.getChildNodes();
final DocumentType docType = doc.getDoctype();
if (docType != null)
{receiver.documentType(docType.getName(), docType.getPublicId(), docType.getSystemId());}
for( int i = 0; i < children.getLength(); i++ ) {
final StoredNode child = (StoredNode)children.item( i );
reader = broker.getXMLStreamReader( child, false );
while( reader.hasNext() ) {
final int status = reader.next();
switch( status ) {
case XMLStreamReader.START_DOCUMENT:
case XMLStreamReader.END_DOCUMENT: {
break;
}
case XMLStreamReader.START_ELEMENT: {
nsdecls = reader.getNamespaceCount();
for( int ni = 0; ni < nsdecls; ni++ ) {
receiver.startPrefixMapping( reader.getNamespacePrefix( ni ), reader.getNamespaceURI( ni ) );
}
final AttrList attribs = new AttrList();
for( int j = 0; j < reader.getAttributeCount(); j++ ) {
final QName qn = new QName( reader.getAttributeLocalName( j ), reader.getAttributeNamespace( j ), reader.getAttributePrefix( j ) );
attribs.addAttribute( qn, reader.getAttributeValue( j ) );
}
receiver.startElement( new QName( reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix() ), attribs );
break;
}
case XMLStreamReader.END_ELEMENT: {
receiver.endElement( new QName( reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix() ) );
nsdecls = reader.getNamespaceCount();
for( int ni = 0; ni < nsdecls; ni++ ) {
receiver.endPrefixMapping( reader.getNamespacePrefix( ni ) );
}
break;
}
case XMLStreamReader.CHARACTERS: {
receiver.characters( reader.getText() );
break;
}
case XMLStreamReader.CDATA: {
ch = reader.getTextCharacters();
receiver.cdataSection( ch, 0, ch.length );
break;
}
case XMLStreamReader.COMMENT: {
ch = reader.getTextCharacters();
receiver.comment( ch, 0, ch.length );
break;
}
case XMLStreamReader.PROCESSING_INSTRUCTION: {
receiver.processingInstruction( reader.getPITarget(), reader.getPIData() );
break;
}
}
if( ( child.getNodeType() == Node.COMMENT_NODE ) || ( child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) ) {