java and XML

T

tony vee

Hi

I have the following bit of Java code:

//Use JTidy implementation to create an empty Document object
Document doc = tidy.createEmptyDocument();
//bodyElement is the body element in an HTML Document
Node first = bodyElement.getFirstChild();
Node top = doc.getDocumentElement();
top.appendChild(first);

which produces unexpected results. Basically, all I am trying to do is
retrieve the first child node contained in the body element and copy it to
the new document element. But what I get is the required element AND every
element after it - every one of the first elements siblings! I have tried so
many variations of the above, using DocumentFragments etc, but with no joy.
In order to preserve the little hair I have left, I would be grateful for
any help

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top