protected void createStartElem ( String nsURI , String prefix , String localName , boolean isEmpty ) throws XMLStreamException { DOMOutputElement elem ; if ( ! mNsAware ) { if ( nsURI != null && nsURI . length ( ) > 0 ) { throwOutputError ( "Can not specify non-empty uri/prefix in non-namespace mode" ) ; } elem = mCurrElem . createAndAttachChild ( mDocument . createElement ( localName ) ) ; } else { if ( mNsRepairing ) { String actPrefix = validateElemPrefix ( prefix , nsURI , mCurrElem ) ; if ( actPrefix != null ) { // fine, an existing binding we can use: if ( actPrefix . length ( ) != 0 ) { elem = mCurrElem . createAndAttachChild ( mDocument . createElementNS ( nsURI , actPrefix + ":" + localName ) ) ; } else { elem = mCurrElem . createAndAttachChild ( mDocument . createElementNS ( nsURI , localName ) ) ; } } else { // nah, need to create a new binding... /* Need to ensure that we'll pass "" as prefix, not null, * so it is understood as "I want to use the default NS", * not as "whatever prefix, I don't care" */ if ( prefix == null ) { prefix = "" ; } actPrefix = generateElemPrefix ( prefix , nsURI , mCurrElem ) ; boolean hasPrefix = ( actPrefix . length ( ) != 0 ) ; if ( hasPrefix ) { localName = actPrefix + ":" + localName ; } elem = mCurrElem . createAndAttachChild ( mDocument . createElementNS ( nsURI , localName ) ) ; /* Hmmh. writeNamespace method requires open element * to be defined. So we'll need to set it first * (will be set again at a later point -- would be * good to refactor this method into separate * sub-classes or so) */ mOpenElement = elem ; // Need to add new ns declaration as well if ( hasPrefix ) { writeNamespace ( actPrefix , nsURI ) ; elem . addPrefix ( actPrefix , nsURI ) ; } else { writeDefaultNamespace ( nsURI ) ; elem . setDefaultNsUri ( nsURI ) ; } } } else { /* Non-repairing; if non-null prefix (including "" to * indicate "no prefix") passed, use as is, otherwise * try to locate the prefix if got namespace. */ if ( prefix == null && nsURI != null && nsURI . length ( ) > 0 ) { prefix = ( mSuggestedPrefixes == null ) ? null : mSuggestedPrefixes . get ( nsURI ) ; if ( prefix == null ) { throwOutputError ( "Can not find prefix for namespace \"" + nsURI + "\"" ) ; } } if ( prefix != null && prefix . length ( ) != 0 ) { localName = prefix + ":" + localName ; } elem = mCurrElem . createAndAttachChild ( mDocument . createElementNS ( nsURI , localName ) ) ; } } /* Got the element; need to make it the open element, and * if it's not an (explicit) empty element, current element as well */ mOpenElement = elem ; if ( ! isEmpty ) { mCurrElem = elem ; } }
Method called by all start element write methods .