I am trying to add elements to xml. I followed Java DOM - Inserting an element, after another but that did not work for me. Here is my code:
Element e = dom.createElement("mapping");
e.setAttribute("resource", "/some/path/to/file");
Element lastChild = (Element)nList.item(nList.getLength()-1);
Element parent= (Element)nList.item(nList.getLength()-1).getParentNode();
lastChild.getParentNode().insertBefore(e, lastChild);
I also tried parent.appendChild(e);
but none of them work. It doesn't seem like there is problem with the code. What could be the problem?
I am using Netbeans on macosx. Is this because of file permissions ?