As noted by others , in Java, with the W3C default DOM libraries, you need to use the Document a factory object for elements, that is:
import org.w3c.dom.Document; import org.w3c.dom.Element; Document d; Element e; e = d.createElement("tag");
Why is this necessary? Why conceptually a method cannot create an XML element without knowing the entire target document? Why can't I just create an instance using "new" or something like that?
source share