question: private static Node locateAttrParent ( Element elem , Node attr ) { Node parent = null ; Attr check = elem . getAttributeNode ( attr . getNodeName ( ) ) ; if ( check == attr ) parent = elem ; if ( null == parent ) { for ( Node node = elem . getFirstChild ( ) ; null != node ; node = node . getNextSibling ( ) ) { if ( Node . ELEMENT_NODE == node . getNodeType ( ) ) { parent = locateAttrParent ( ( Element ) node , attr ) ; if ( null != parent ) break ; } } } return parent ; }
target:  Support for getParentOfNode; walks a DOM tree until it finds the Element which owns the Attr. This is hugely expensive, and if at all possible you should use the DOM Level 2 Attr.ownerElement() method instead. <p> The DOM Level 1 developers expected that folks would keep track of the last Element they'd seen and could recover the info from that source. Obviously that doesn't work very well if the only information you've been presented with is the Attr. The DOM Level 2 getOwnerElement() method fixes that, but only for Level 2 and later DOMs.