private void domToSax ( final Element elem , final boolean retainElements , final boolean swapMapClass ) throws SAXException { if ( retainElements ) { final AttributesImpl atts = new AttributesImpl ( ) ; final NamedNodeMap attrs = elem . getAttributes ( ) ; for ( int i = 0 ; i < attrs . getLength ( ) ; i ++ ) { final Attr a = ( Attr ) attrs . item ( i ) ; if ( a . getNodeName ( ) . equals ( ATTRIBUTE_NAME_CLASS ) && swapMapClass ) { XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_CLASS , changeclassValue ( a . getNodeValue ( ) ) ) ; } else { XMLUtils . addOrSetAttribute ( atts , a ) ; } } getContentHandler ( ) . startElement ( NULL_NS_URI , elem . getNodeName ( ) , elem . getNodeName ( ) , atts ) ; } final NodeList nodeList = elem . getChildNodes ( ) ; for ( int i = 0 ; i < nodeList . getLength ( ) ; i ++ ) { final Node node = nodeList . item ( i ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { final Element e = ( Element ) node ; // retain tm and text elements if ( TOPIC_TM . matches ( e ) || TOPIC_TEXT . matches ( e ) ) { domToSax ( e , true , swapMapClass ) ; } else { domToSax ( e , retainElements , swapMapClass ) ; } } else if ( node . getNodeType ( ) == Node . TEXT_NODE ) { final char [ ] ch = node . getNodeValue ( ) . toCharArray ( ) ; getContentHandler ( ) . characters ( ch , 0 , ch . length ) ; } } if ( retainElements ) { getContentHandler ( ) . endElement ( NULL_NS_URI , elem . getNodeName ( ) , elem . getNodeName ( ) ) ; } }
Serialize DOM node into a SAX stream .