From: SourceForge.net <no...@so...> - 2010-10-27 03:52:10
|
Bugs item #3071265, was opened at 2010-09-19 22:16 Message generated for change (Comment added) made by aditsu You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=113153&aid=3071265&group_id=13153 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Martin (martinkurz) >Assigned to: Adrian Sandor (aditsu) Summary: NPE on appendChild with attribute node Initial Comment: for problem description see http://sourceforge.net/projects/jtidy/forums/forum/41437/topic/3787602 analysis: on appending a new child, the new child nodes type is checked on field adaptee.type, in attribute nodes, this is null (the field is called avAadaptee instead) solution: first check, if new childnode is an attribute node before checking adaptee.type, patch for java5 branch including testcase attached ---------------------------------------------------------------------- >Comment By: Adrian Sandor (aditsu) Date: 2010-10-27 11:52 Message: I don't think you're supposed to be able to use appendChild with an attribute node. See the program below for a demonstration (including how it should be done instead): import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class TestAppendAttr { public static void main(final String... args) throws Exception { final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); final Element html = doc.createElement("html"); doc.appendChild(html); final Element body = doc.createElement("body"); html.appendChild(body); final Element a = doc.createElement("a"); body.appendChild(a); a.setAttribute("href", "foo"); // correct final Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(doc), new StreamResult(System.out)); // just to see the result final Attr target = doc.createAttribute("target"); target.setValue("_blank"); a.appendChild(target); // DOMException } } Let me know if I missed anything. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=113153&aid=3071265&group_id=13153 |