It seems that what you are looking for is a generic "xml diff"
This is a very difficult problem to solve generically.
You can compare 2 xml documents with fn:deep-equal ()
https://docs.marklogic.com/fn:deep-equal

But that doesnt give you the diff, only a true/false

To do a real XML diff is very tedious and I havent, myself, found any ideal 
solution to it.
If you know a lot about your data structure the problem becomes easier.
In this case if you are only looking at specific elements you can iterate over 
2 trees in xquery and print out where they start to differ.

Googling for "xquery compare xml"  I found some examples, but mostly statements 
that its not an easy problem.
A core issue is that your asking for a tree compare not a line compare.
Line compares/diffs are a well solved problem (see diff ...)
Tree compares suffer from the complexity of trees ... and what defines 
equivalence ... for example sometimes you care
if elements are in a different order sometimes you do not.  Finding the minimal 
difference is very challenging.

Is it possible you might be able to work with a simpler solution such as 
deep-equal() ?



-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Singh, Gurbeer
Sent: Wednesday, August 21, 2013 5:44 PM
To: [email protected]
Subject: [MarkLogic Dev General] Compare XML

Is there any way to compare my XML ,without writing any custom code to 
enumerate for all elements

Let say I have a XML like this

<root>
<version id="1">
<ele1>12</ ele1>
< ele2>34</ ele2>
< ele3>56</ ele3>
</version>
<version id="2">
<ele1>12</ ele1>
< ele2>43</ ele2>
< ele3>55</ ele3>
</version>
</root>

I want result as ele2 ,ele3

~Gurbeer

________________________________

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or 
views contained herein are not intended to be, and do not constitute, advice 
within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and 
Consumer Protection Act. If you have received this communication in error, 
please destroy all electronic and paper copies and notify the sender 
immediately. Mistransmission is not intended to waive confidentiality or 
privilege. Morgan Stanley reserves the right, to the extent permitted under 
applicable law, to monitor electronic communications. This message is subject 
to terms available at the following link: 
http://www.morganstanley.com/disclaimers If you cannot access these links, 
please notify us by reply message and we will send the contents to you. By 
messaging with Morgan Stanley you consent to the foregoing.
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to