-----Original Message-----
From: McDonough, Michael [mailto:[EMAIL PROTECTED]
Sent: Friday, January 09, 2004 11:02 AM
To: Bradley, Martin; [EMAIL PROTECTED]
Subject: RE: [dom4j-user] Create an Document from fragments of anotherYes... There is also a detach() method that I imagine nulls a Nodes reference to any "parent", which I usually call when copying nodes from one tree to another. Forgot to mention that!
Glad you're making progress.
-----Original Message-----
From: Bradley, Martin [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 09, 2004 10:48 AM
To: [EMAIL PROTECTED]
Subject: RE: [dom4j-user] Create an Document from fragments of another
Naveen & Michael, thanks.
The a1.CreateCopy did the trick...
If I try to add the element to the root of another document then I get and IllegalAddException. Saying the the original node already has a parent. As usual, it all makes sense once it works!
Thanks again,
Marty-----Original Message-----
From: Naveen Murthy [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 09, 2004 10:11 AM
To: Bradley, Martin
Subject: RE: [dom4j-user] Create an Document from fragments of another
Marty,
ive been out of dom4j prgramming for a while..
Im sure ive done this before. But i vaguely remember the syntax ..TRY thishere is the steps:
1. get a reference to the a1 element
Element a1 = origDOM.element("a1");2. create a copy of a1 and add it to new DOM
newDOM.getRoot().addElement(a1.createCopy() ) ;
i think this should do the trick.
thx,
Naveen-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Bradley,
Martin
Sent: Friday, January 09, 2004 10:00 AM
To: [EMAIL PROTECTED]
Subject: [dom4j-user] Create an Document from fragments of another
Hi all,
I seem to be stumped on this one. I haven't been using the dom4j api long and I'm having trouble pulling a node set our of one document and then using it to create another. for example I have the following xml:
<aaa>
<a1>
<bbb />
<ccc />
</a1>
<a1>
<bbb />
<ccc />
</a1>
</aaa>I want to pick up the first a1 and create a document as follows:
<onlyone>
<a1>
<bbb />
<ccc />
</a1>
</onlyone>What I get is:
<onlyone>
<bbb />
<ccc />
</onlyone>
Here's the code (removed try...catch for brevity)SAXReader reader = new SAXReader();
Document inDoc = reader.read(f);
List selectedList = inDoc.selectNodes("aaa/a1");
Iterator suspects = selectedList.iterator();for (;suspects.hasNext();)
{
Branch treeFragment = (Branch)suspects.next();Document document = DocumentHelper.createDocument();
Element root = DocumentHelper.createElement("suspect");
document.setRootElement(root);root.appendContent(treeFragment);
System.out.println(document.asXML());
}Any ideas? Am i missing something obvious? Thanks for any help,
Marty
NOTICE: This E-mail may contain confidential information. If you are not
the addressee or the intended recipient please do not read this E-mail
and please immediately delete this e-mail message and any attachments
from your workstation or network mail system. If you are the addressee
or the intended recipient and you save or print a copy of this E-mail,
please place it in an appropriate file, depending on whether
confidential information is contained in the message.
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÓ?+ùÞµésSX¬²s'²SÞu¼ÿ=êߢ·J?íÁªÞü÷«~SÜz+-...áZ²Ô¨~Üà¨ø º¶S?Ìjv zg§µ,¬µé¨}÷«Sxvö§qç[©Ü?)àqªZn)b¶'¬jwZ¶?¢qÈZz¬¢~tú(tm)Zµú+sÏÅç"½©ÿ?ÛiÿÿðÃéz·èÇÿr?¿¥êߢ·þZvsèføms_ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿýÚ&â?î±êæj)bz b²×h>^ÿºÇ«þX¬¶Ïì¢êÜyú+ïçzØm¶>ÿÿùb²Ûÿ²<«qçè®ÿë-+-³ùb²Ø§~Ý¢n#þë
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user
Title: RE: [dom4j-user] Create an Document from fragments of another
I'll
give detach a shot too. Seems to make sense if I don't need to get
back to the original parent. Thanks
- [dom4j-user] Create an Document from fragments of another Bradley, Martin
- RE: [dom4j-user] Create an Document from fragments of... Bradley, Martin
- Bradley, Martin