public void addAttribute ( String uri , String localName , String rawName , String type , String value , boolean xslAttribute ) throws SAXException { if ( m_elemContext . m_startTagOpen ) { boolean was_added = addAttributeAlways ( uri , localName , rawName , type , value , xslAttribute ) ; /* * We don't run this block of code if: * 1. The attribute value was only replaced (was_added is false). * 2. The attribute is from an xsl:attribute element (that is handled * in the addAttributeAlways() call just above. * 3. The name starts with "xmlns", i.e. it is a namespace declaration. */ if ( was_added && ! xslAttribute && ! rawName . startsWith ( "xmlns" ) ) { String prefixUsed = ensureAttributesNamespaceIsDeclared ( uri , localName , rawName ) ; if ( prefixUsed != null && rawName != null && ! rawName . startsWith ( prefixUsed ) ) { // use a different raw name, with the prefix used in the // generated namespace declaration rawName = prefixUsed + ":" + localName ; } } addAttributeAlways ( uri , localName , rawName , type , value , xslAttribute ) ; } else { /* * The startTag is closed, yet we are adding an attribute? * * Section: 7.1.3 Creating Attributes Adding an attribute to an * element after a PI (for example) has been added to it is an * error. The attributes can be ignored. The spec doesn't explicitly * say this is disallowed, as it does for child elements, but it * makes sense to have the same treatment. * * We choose to ignore the attribute which is added too late. */ // Generate a warning of the ignored attributes // Create the warning message String msg = Utils . messages . createMessage ( MsgKey . ER_ILLEGAL_ATTRIBUTE_POSITION , new Object [ ] { localName } ) ; try { // Prepare to issue the warning message Transformer tran = super . getTransformer ( ) ; ErrorListener errHandler = tran . getErrorListener ( ) ; // Issue the warning message if ( null != errHandler && m_sourceLocator != null ) errHandler . warning ( new TransformerException ( msg , m_sourceLocator ) ) ; else System . out . println ( msg ) ; } catch ( TransformerException e ) { // A user defined error handler, errHandler, may throw // a TransformerException if it chooses to, and if it does // we will wrap it with a SAXException and re-throw. // Of course if the handler throws another type of // exception, like a RuntimeException, then that is OK too. SAXException se = new SAXException ( e ) ; throw se ; } } }
Add an attribute to the current element .