public ISynchronizationPoint < IOException > start ( String rootNamespaceURI , String rootLocalName , Map < String , String > namespaces ) { if ( includeXMLDeclaration ) { writer . write ( XML_DECLARATION_START ) ; writer . write ( output . getEncoding ( ) . name ( ) ) ; writer . write ( XML_DECLARATION_END ) ; } writer . write ( ' ' ) ; if ( rootNamespaceURI != null ) { String ns = namespaces . get ( rootNamespaceURI ) ; if ( ns != null && ns . length ( ) > 0 ) { writer . write ( ns ) ; writer . write ( ' ' ) ; } } ISynchronizationPoint < IOException > result = writer . write ( rootLocalName ) ; if ( namespaces != null && ! namespaces . isEmpty ( ) ) { for ( Map . Entry < String , String > ns : namespaces . entrySet ( ) ) { writer . write ( XMLNS ) ; if ( ns . getValue ( ) . length ( ) > 0 ) { writer . write ( ' ' ) ; writer . write ( ns . getValue ( ) ) ; } writer . write ( ATTRIBUTE_EQUALS ) ; writer . write ( escape ( ns . getKey ( ) ) ) ; result = writer . write ( ' ' ) ; } } Context ctx = new Context ( ) ; ctx . namespaces = new HashMap <> ( ) ; if ( namespaces != null ) ctx . namespaces . putAll ( namespaces ) ; ctx . namespaceURI = rootNamespaceURI ; ctx . localName = rootLocalName ; ctx . open = true ; context . addFirst ( ctx ) ; return result ; }
Start the document with the XML processing instruction if needed and opening the root element .