private static Map < String , String > getAttributeMap ( Node parent , String nodeName , String keyAttributeName , String valueAttributeName ) throws AppEngineException { Map < String , String > nameValueAttributeMap = new HashMap <> ( ) ; if ( parent . hasChildNodes ( ) ) { for ( int i = 0 ; i < parent . getChildNodes ( ) . getLength ( ) ; i ++ ) { Node child = parent . getChildNodes ( ) . item ( i ) ; NamedNodeMap attributeMap = child . getAttributes ( ) ; if ( nodeName . equals ( child . getNodeName ( ) ) && attributeMap != null ) { Node keyNode = attributeMap . getNamedItem ( keyAttributeName ) ; if ( keyNode != null ) { Node valueNode = attributeMap . getNamedItem ( valueAttributeName ) ; try { nameValueAttributeMap . put ( keyNode . getTextContent ( ) , valueNode . getTextContent ( ) ) ; } catch ( DOMException ex ) { throw new AppEngineException ( "Failed to parse value from attribute node " + keyNode . getNodeName ( ) , ex ) ; } } } } } return nameValueAttributeMap ; }
Returns a map formed from the attributes of the nodes contained within the parent node .