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.
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:
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.
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
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.
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, that will fit in a stocking