public void toXML ( XMLBuilder xml ) throws IllegalArgumentException { assert xml != null ; // Determine what tag name to use for the generated element. Map < String , String > attrMap = new LinkedHashMap <> ( ) ; String elemName = m_name ; if ( m_tagName . length ( ) > 0 ) { // Place m_name into a "name" attribute and use m_tagName attrMap . put ( "name" , m_name ) ; elemName = m_tagName ; } // Add child VALUE nodes marked as "attribute" in its own map. addXMLAttributes ( attrMap ) ; switch ( m_type ) { case ARRAY : // Start an element with or without attributes. if ( attrMap . size ( ) > 0 ) { xml . startElement ( elemName , attrMap ) ; } else { xml . startElement ( elemName ) ; } // Add XML for non-attribute child nodes. if ( m_children != null ) { for ( UNode childNode : m_children ) { if ( childNode . m_type != NodeType . VALUE || ! childNode . m_bAttribute ) { childNode . toXML ( xml ) ; } } } xml . endElement ( ) ; break ; case MAP : // Start an element with or without attributes. if ( attrMap . size ( ) > 0 ) { xml . startElement ( elemName , attrMap ) ; } else { xml . startElement ( elemName ) ; } // Add XML for non-attribute child nodes in name order. if ( m_childNodeMap != null ) { assert m_childNodeMap . size ( ) == m_children . size ( ) ; for ( UNode childNode : m_childNodeMap . values ( ) ) { if ( childNode . m_type != NodeType . VALUE || ! childNode . m_bAttribute ) { childNode . toXML ( xml ) ; } } } xml . endElement ( ) ; break ; case VALUE : // Map to a simple element. String value = m_value ; if ( Utils . containsIllegalXML ( value ) ) { value = Utils . base64FromString ( m_value ) ; attrMap . put ( "encoding" , "base64" ) ; } if ( attrMap . size ( ) > 0 ) { xml . addDataElement ( elemName , value , attrMap ) ; } else { xml . addDataElement ( elemName , value ) ; } break ; default : assert false : "Unexpected NodeType: " + m_type ; } }
Add the XML required for this node to the given XMLBuilder .