Re: merging two XMLs in java
"\"Christopher (siege) \"O'Brien" <[email protected]> Wed, 10 Jul 2002 14:38:04 -0400
| Newsgroups | gmane.comp.windows.devel.java.general |
|---|---|
| Message-ID | <1026326284.2018.11.camel@stella> |
See the Document.importNode(Node) method -->
http://java.sun.com/j2se/1.4/docs/api/org/w3c/dom/Document.html#importNode(org.w3c.dom.Node, boolean)
You have to import a node into a document before you can add it to it.
As for turning it into a String, try using a StringWriter...
Document doc = myDocument();
StringWriter sw = new StringWriter();
TransformerFactory.newInstance().newTransformer()
.transform(new DOMSource(doc), new StreamResult(sw));
String xml_string = sw.toString();
Hope this helps
-Chris
On Wed, 2002-07-10 at 13:36, Bernhard Gruber wrote:
> hi all
>
> my task is, to merge two (or more) different XML-Documents to one (which I
> want to return as a String (!!!)
>
> i use
>
> oracle.xml.parser.v2.*;
> org.w3c.dom.*;
>
> walking through the single XMLs works perfectly and getting the Nodes (and
> Nodelists) I want to put together in one Doc works also -->
> BUT when i try to append one of the detected Nodes (somewhere) in the
> XMLDocument, which should put everything together I get :
>
> oracle.xml.parser.v2.XMLDOMException: Node doesn't belong to the current
> document.
>
> can anybody help me ??
> By the way : I doent really know the correct way to get a String from an
> XMLDocument
>
> tnx
>
> bernie
>
>
> You can read messages from the JAVA archive, unsubscribe from JAVA,
> or subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.