The dom4j API more or less makes the assumption that you're loading the
document into memory.(at least for the DOM part) Something simple like
you're doing is probably better addressed with XSLT. Might want to
google "merging documents with XSLT".
I'm not sure, but dom4j with a pull parser MIGHT work for this. My
understanding is that a pull parser only loads what it needs from the
document into memory, but I'm not sure if you clone an entire document
if it loads that whole thing. It would probably be easier and much
faster to use the nio package or some unix commands.
--Evan
Håkan Jacobsson wrote:
Muzaffer,
Yes, thats true. I could try this.
Is there no way to do this kind of merging using the dom4j
API?
/Håkan
----Ursprungligt meddelande----
Från: [EMAIL PROTECTED]
Datum: 15-01-2008 16:29
Till: "[email protected]"<[EMAIL PROTECTED]
sourceforge.net>
Ärende: Re: [dom4j-user] Merging several XML-files
If your XML is that simple and nicely structured, you can
write regular expressions (or use similar text operations) to
extract the <product> sections and put them back to back and
slap a <rootelement> </rootelement> to the beginning and the
end. If you keep the result in the memory, it's still going to
be a large String, so you might want to write the XML to a file
as you process your input.
I don't know that's the best approach but with a simple XML,
it seems pretty easy to implement.
Muzaffer
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:
dom4j-user-
[EMAIL PROTECTED]] On Behalf Of Håkan Jacobsson
Sent: Tuesday, January 15, 2008 7:39 AM
To: [email protected]
Subject: [dom4j-user] Merging several XML-files
Hi,
What would be the best approach to merging several XML
files?
The files are big, so I can't keep them in memory.
Example:
xml document 1:
<rootelement>
<product>
<data>somedata</data>
</product>
</rootelement>
xml document 2:
<rootelement>
<product>
<data>someotherdata</data>
</product>
</rootelement>
result.xml:
<rootelement>
<product>
<data>somedata</data>
</product>
<product>
<data>someotherdata</data>
</product>
</rootelement>
That is, I just want to append all elements below the root
element from file2, 3 etc. into file1 (just before the
</rootelement> tag).
When all data from file2,3 etc.is appended I would append
the
</rootelement> tag.
/Best regards, Håkan Jacobsson - System developer in Sweden
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http:
//sf.net/marketplace
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user
|
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user