protected void isAttributeWellFormed ( Node node ) { boolean isNameWF = false ; if ( ( fFeatures & NAMESPACES ) != 0 ) { isNameWF = isValidQName ( node . getPrefix ( ) , node . getLocalName ( ) , fIsXMLVersion11 ) ; } else { isNameWF = isXMLName ( node . getNodeName ( ) , fIsXMLVersion11 ) ; } if ( ! isNameWF ) { String msg = Utils . messages . createMessage ( MsgKey . ER_WF_INVALID_CHARACTER_IN_NODE_NAME , new Object [ ] { "Attr" , node . getNodeName ( ) } ) ; if ( fErrorHandler != null ) { fErrorHandler . handleError ( new DOMErrorImpl ( DOMError . SEVERITY_FATAL_ERROR , msg , MsgKey . ER_WF_INVALID_CHARACTER_IN_NODE_NAME , null , null , null ) ) ; } } // Check the Attr's node value // WFC: No < in Attribute Values String value = node . getNodeValue ( ) ; if ( value . indexOf ( ' ' ) >= 0 ) { String msg = Utils . messages . createMessage ( MsgKey . ER_WF_LT_IN_ATTVAL , new Object [ ] { ( ( Attr ) node ) . getOwnerElement ( ) . getNodeName ( ) , node . getNodeName ( ) } ) ; if ( fErrorHandler != null ) { fErrorHandler . handleError ( new DOMErrorImpl ( DOMError . SEVERITY_FATAL_ERROR , msg , MsgKey . ER_WF_LT_IN_ATTVAL , null , null , null ) ) ; } } // we need to loop through the children of attr nodes and check their values for // well-formedness NodeList children = node . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node child = children . item ( i ) ; // An attribute node with no text or entity ref child for example // doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ns"); // followes by // element.setAttributeNodeNS(attribute); // can potentially lead to this situation. If the attribute // was a prefix Namespace attribute declaration then then DOM Core // should have some exception defined for this. if ( child == null ) { // we should probably report an error continue ; } switch ( child . getNodeType ( ) ) { case Node . TEXT_NODE : isTextWellFormed ( ( Text ) child ) ; break ; case Node . ENTITY_REFERENCE_NODE : isEntityReferneceWellFormed ( ( EntityReference ) child ) ; break ; default : } } // TODO: // WFC: Check if the attribute prefix is bound to // http://www.w3.org/2000/xmlns/ // WFC: Unique Att Spec // Perhaps pass a seen boolean value to this method. serializeAttList will determine // if the attr was seen before. }
Checks if an attr node is well - formed by checking it s Name and value for well - formedness .