question: private static Element addElement ( Document doc , Node parent , String tagName , String attr1 , String val1 , String attr2 , String val2 ) { Element elem = doc . createElement ( tagName ) ; if ( attr1 != null ) elem . setAttribute ( attr1 , val1 ) ; if ( attr2 != null ) elem . setAttribute ( attr2 , val2 ) ; parent . appendChild ( elem ) ; return elem ; }
target:  Add element to XML document.