From: SourceForge.net <no...@so...> - 2010-07-28 18:58:31
|
The following forum message was posted by Anonymous at http://sourceforge.net/projects/jtidy/forums/forum/41437/topic/3787602: When I attempt to append a new attribute node onto a specific node, I get a null pointer exception from within jtidy -- Am I not initializing something or is there a bug? Here is my code: private void addTarget_blank(Document doc){ NodeList list = doc.getElementsByTagName(\"a\"); for(int i=0; i<list.getLength(); i++){ NamedNodeMap map = list.item(i).getAttributes(); for (int j = 0; j < map.getLength(); j++) { if(map.getNamedItem(\"target\") == null){ Attr attr = doc.createAttribute(\"target\"); attr.setNodeValue(\"_blank\"); attr.setValue(\"_blank\"); list.item(i).appendChild(attr); } } } } |