This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have two differnet xmls - each with different sets of nodes.
ex reply1.xml has nodes like id, name age,account
reply2.xml has nodes like startdate,enddate.
I need to merge them in a single xml. Currently I am doing this
XMLNode ReplyNode1= super.returnXml(Id);
(This reads from repy1.xml)
XMLNode ReplyNode2= returnXml(Id);
(This reads from repy2.xml)
So obviously you can't do that. Let's look at the requirements more carefully then. (I didn't really see any requirements in your post, though, so I'm going with the title of the thread as your requirements.)
First of all, as you probably know an XML document can only have a single root element. So the result of merging two XML documents, each of which has a single root element, can itself have only a single root element. So what is it going to be? The root of the first document? The root of the second document? Something different?
Okay, let's suppose you have that requirement taken care of. Let's suppose you're generating a new root element for the result document. Then what is supposed to happen to the root elements of the two input documents. Do they get discarded? Or are they used as the only two children of the result document's root?
Okay. Let's suppose you have that requirement taken care of. Let's suppose that the root elements of the two input documents get discarded. Then presumably you want to take all of the child nodes of those two roots and make them be child nodes of the result document's root. What order do you want them to be in? First document's nodes then second document's nodes? Or something else? And do you want anything special done with whitespace text nodes?
Now I might have chosen the wrong questions to ask, because the questions I asked depended on the answers I guessed for earlier questions. But the point is that it's up to you to ask those questions. Right now you don't know what your requirements are, so you don't know what to do. In which case there is no point in writing code. Get the requirements written down first.
Devesh Shekhar Gupta
Joined: Nov 24, 2009
I have two xml's and need to merge them in third new xml.
The roots of both the xml's will be discarded and a new xml root will be generated.
The child elements of both the xml's will now be child elemnts of new root.
First the roots of first xml be added then that of second xml.Nothing special neds to be done about whitespace text nodes