Java and XML newbie

T

tony vee

Hi

I have a number of element objects contained in a document object. I am
trying to extract some of these nodes from the document object, and add them
to a new DocumentFragment like so:

Element firstNode = document.getDocumentElement();
DocumentFragment docFrag = document.createDocumentFragment();
docFrag.appendChild(docFrag); //this line throws nullPointerException

but I get a null pointer exception, since docFrag is null. How do I
instantiate a docFrag in order to be able to append a child node to it?

Also, since I am mainly working with HTML files, is there a better API to
use other than the org.w3c.dom API, which is what I am using at the moment.

Thanks

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top