It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes Overloading a XML file with another XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Overloading a XML file with another XML" Watch "Overloading a XML file with another XML" New topic

Overloading a XML file with another XML

Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi guys!

I know, I already posted this problem, some time ago, but I mistakenly though, I found the solution. But, I didn´t
So basically, to shortly recap what I want to do: I have 2 XML file. Both files have a similar named section. What I want to do is, to replace section A from file A with section A from file B.
To illustrate:

File A:

File B:

The similar named section, both have in common is <note>, but the contained attributes differ from file to file.
File B is just the section, I want to place inside File A,nothing more, while File A is a HUGE file,where you have to locate the correct section first before overloading it.
The overloading process would be perfect if I would save the result in an entirely new XML, not actually overwriting the existing file.

I tried this for weeks now and I just can´t figure this one out...All I got so far was, to append the wanted section to the right file, but that´s still not it...
And the replaceChild(), adoptChild() won´t work too...

Here´s my code so far,hopefully somebody finds the mistake

No matter what I try,it just won´t work...And I already tried a lot of System.out.print-statements to figure this one out,trust me ;)


Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Won't work? What makes you think that?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 632

Notes: I don't see what does it mean by "variableParameters" and I suppose it means "note" in the description. Due to that uncertainty, I use dup.getNodeName() to avoid that uncertainty supposing the replacement is on the same name basis. Also, you've to insert a layer of getDocumentElement() to avoid "note" being the root node of the "biggerXML" file A. If that happens, no replacement would take place but the construction avoids runtime error neither. Those details you can simplify a bit as long as you clean up the messy bit of the code.
Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi guys!

It worked
Big Thank You to g tsuji
That´s EXACTLY what caused the problem!
For everybody who is looking for the complete solution, here´s the code:

I agree. Here's the link:
subject: Overloading a XML file with another XML
jQuery in Action, 3rd edition