• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Overwriting XML Section

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys!

Some time ago,I tried to find a solution for overwriting a special section inside a big XML with another smaller XML.
Now,I tried and tried,but somehow,my code just won´t work.It doesn´t replace the XML section,it only appends the small XML at the end of the big XML.
Here´s my code:



Does anyone see the problem??I mean,the XMLs are both wellformed and I just can´t see why my program just appends the XML section to the big XML instead of replacing the section with the same name as the replacing section xml inside the big XML.

I hope,you can help me!

Greetings,

Randy
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API documentation for appendChild():

Adds the node newChild to the end of the list of children of this node.



If you want to replace a node, I suggest you consider a method which has "replace" in its name. Check the API documentation for that one.
 
Randy Miller
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah,ok,now that explains why the node is appended at the end of the file.
So,I tried to get it to work with the replaceChild() method,but still it won´t work. Just won´t replace it and the program doesn´t really wanna jump into my saving-method(Transformer stuff^^)
Here´s my next try:


 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I have to say that I don't understand your code. Based on what you said earlier and based on some of the variable names, I have a vague feeling that maybe you should be trying to replace one of the nodes of doc2 by the contents of doc1, rather than what you're doing now. But calling the documents "doc1" and "doc2" is quite unhelpful.
 
Randy Miller
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul!

Sorry for the unclear code ;)
I tried to name the deciding elements a bit differently, so it´s easier to understand.And I also put the saving mechanism into a new function.



But somehow,still I just won´t get it to work correctly.The save-operation won´t even be triggered and I haven´t figured out yet,if the overwriting mechanism works...
Maybe,now,it´s easier to see the problem for one of you?
Meanwhile,should I find the solution,I´ll post it right here
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So line 12 says you start with "replacementDoc". At line 13 you get all of the children of that document's document node. If one of those children has a node name which matches what you're looking for (line 19) then you attempt to replace that child by this expression:



Right so far?

Well, first of all there is no point in importing into the entireDoc document, since that isn't the one you're working with. You're working with replacementDoc (see line 12). So all you need there is this:



But now this can't work because you're trying to move the document element to be a child of itself.
reply
    Bookmark Topic Watch Topic
  • New Topic