xml order of nodes not c

31 views
Skip to first unread message

Rahul Raina

unread,
Jun 24, 2014, 12:38:01 PM6/24/14
to prett...@googlegroups.com
If i have two xml's in which the order of nodes are different can it be somehow sorted so that it doesn't display as differences.

Cheney, Edward A SFC USARMY (US)

unread,
Jun 24, 2014, 3:48:18 PM6/24/14
to prett...@googlegroups.com
Rahul,

Could you provide some sample code for me to examine?

Thanks,
Austin
________________________________________
From: prett...@googlegroups.com [prett...@googlegroups.com] on behalf of Rahul Raina [raina....@gmail.com]
Sent: Tuesday, June 24, 2014 11:38 AM
To: prett...@googlegroups.com
Subject: [Pretty Diff] xml order of nodes not c

If i have two xml's in which the order of nodes are different can it be somehow sorted so that it doesn't display as differences.

--
You received this message because you are subscribed to the Google Groups "Pretty Diff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretty-diff...@googlegroups.com.
To post to this group, send email to prett...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretty-diff/e9bcabad-3a64-47c0-b549-65499928aed0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rahul Raina

unread,
Jun 25, 2014, 12:43:47 PM6/25/14
to prett...@googlegroups.com
Lets say xml 1:
<a>
<b value="1">
<subnode/>
</b>
<c value="1">
<subnode/>
</c>
<d value="1">
<subnode/>
</d>
</a>

xml 2:

<a>
<c value="1">
<subnode/>
</c>
<d value="1">
<subnode/>
</d>
<b value="1">
<subnode/>
</b>
</a>


This is a very basic example and we can easily sort out the ordering of the node by the human eye, but lets say I have huge xml's and I am certain that both have a set of nodes in a different order.

Some how both first sorted in a particular order and then compared.

Cheney, Edward A SFC USARMY (US)

unread,
Jun 27, 2014, 8:31:16 AM6/27/14
to prett...@googlegroups.com
Rahul,

I could do this. My current parser represents nodes in a list of a flat array instead of true lambda representation. This means that while the parser is robust enough for enhancements like this, it would take a large algorithmic effort. I don't know when I can get around to this, but I will let you know when I do.

Austin
________________________________________
From: prett...@googlegroups.com [prett...@googlegroups.com] on behalf of Rahul Raina [raina....@gmail.com]

Sent: Wednesday, June 25, 2014 11:43 AM
To: prett...@googlegroups.com
Subject: Re: [Pretty Diff] xml order of nodes not c

xml 2:

To view this discussion on the web visit https://groups.google.com/d/msgid/pretty-diff/6952aca9-5e6a-4ed4-bde7-a443e243d272%40googlegroups.com.

Message has been deleted

Rahul Raina

unread,
Jul 8, 2014, 12:13:52 PM7/8/14
to prett...@googlegroups.com
Hi,
I have seen your javascript code on Github . I am new to Javascript, and the code is pretty confusing. As it has lots of methods for lots of various task, could you tell me the particular method I need for only xml comparison but not for minimizing or beautifying. I only need to build a xml comparison tool, and my be try to put a logic for sorting out xml in that.

It would be of great help.

Rahul

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Cheney, Edward A SFC USARMY (US)

unread,
Jul 9, 2014, 10:21:23 PM7/9/14
to prett...@googlegroups.com
Rahul,

I include each of my libraries directly in the primary application file: prettydiff.js. You can access the library files individually with more documentation in the "lib" directory.

The library that compares code is diffview.js. The library that beautifies XML is markup_beauty.js.
https://github.com/austincheney/Pretty-Diff/blob/master/lib/diffview.js
https://github.com/austincheney/Pretty-Diff/blob/master/lib/markup_beauty.js

Regardless of whether or not you are new to JavaScript I would imagine the diffview.js file is very challenging to read. It is really 3 large algorithms:

* opcodes - This algorithm identifies on which lines of code changes have occurred and identifies for those lines as equal (no change), replace (one for one change), insert (a new line of code), delete (a long of code is removed). The output is an array of arrays where each array is the prior mentioned status and 4 numbers indicating starting and stopping lines for the given status in each code sample.

* charcomp - This is a complex fuzzy string comparison algorithm used to identify and highlight character differences on lines with the status "replace"

* report - This function uses the opcodes output to draw an HTML table diff report and calls the charcomp function. It also provides additional logic to draw the table appropriately for the "inline" or "side-by-side" view options and provide two forms of interaction upon the table.

Please let me know if you have any questions,


Austin
________________________________________
From: prett...@googlegroups.com [prett...@googlegroups.com] on behalf of Rahul Raina [raina....@gmail.com]

Sent: Tuesday, July 08, 2014 11:14 AM
To: prett...@googlegroups.com
Subject: RE: [Pretty Diff] xml order of nodes not c

Rahul

--


You received this message because you are subscribed to the Google Groups "Pretty Diff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretty-diff...@googlegroups.com.
To post to this group, send email to prett...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/pretty-diff/a7cb3f25-babf-4913-b3a2-28fc700596b1%40googlegroups.com.

Rahul Raina

unread,
Jul 13, 2014, 6:38:58 AM7/13/14
to prett...@googlegroups.com
Hi,
Austin:

Thanks for the reply.
Could you break it down a little more for me in order for me to know how each of these functions work independently .
Say I am giving two xml's to the application which would be strings "xml1" and "xml2".

From what I know I need to pickup the functions (opcodes, charcomp, report) from the application independently . I guess the markup-beauty is pretty straightforward it
would pick up the string and beautify it and again give a string.

What I need to know is that what does the functions opcodes, charcomp and report accept as a input and what do they return, and in what order . What I
meant to know is that say opcodes accepts the string after markup-beauty has done its job and return an array or something and which passes to charcomp.

Something like this would be very helpful. A big thank you in advance :)

Message has been deleted

Rahul Raina

unread,
Jul 15, 2014, 7:16:09 AM7/15/14
to prett...@googlegroups.com
and also I can't get the diffview function to run.

I passed it with this arguments.

args1={
source: "<a>hello</a>",
diff : "<a>Hello..!!</a>",
lang : "markup"
};


and I get this output:

Base Source

New Source

Diff view written by Pretty Diff.

00


Here is a jsfiddle link too.
http://jsfiddle.net/cJ6b3/

Cheney, Edward A SFC USARMY (US)

unread,
Jul 15, 2014, 4:57:13 PM7/15/14
to prett...@googlegroups.com
Rahul,

The diffview function, receives as input one object for an argument. This object contains the properties:

* baseTextLines - string, the base code to compare
* newTextLines - string, the other code to compare
* baseTextName - string, a label to describe or name the code in "baseTextLines"
* newTextName - string, a label to describe or name the code in "newTextLines"
* inline - boolean, if true there is one column diff report showing differences in a vertical line by line comparison instead of horizontally side by side

The order of operations is as follows:

1) The code inputs are split into an array of lines of text in the stringAsLines function

2) The opcodes function receives no input and looks to "baseTextArray" and "newTextArray" as closures. It does several different things to examine for which lines are comparable. There is a lot of refinement and error correction in here, but really 80% of what matters is one line:
https://github.com/austincheney/Pretty-Diff/blob/master/lib/diffview.js#L187

3) opcodes returns an array of arrays. The schema for each index (collect of different lines) looks like:
[status, start line of of base, end line of base, start line of new, end line of new]

* status is a string: "replace", "insert", "delete", or "equal"
* The remaining four indexes are number types

4) The diffreport runs automatically without being called once the opcodes are generated. The diffreport writes the HTML output using the opcodes as a closure. The diffreport takes no input or arguments. The diffview library returns the diffreport function, which is a self invoking function that generates and returns a string of HTML output.

5) Each time diffreport encounters a status of "replace" it runs charcomp

6) The charcomp function requires an array of two strings to compare and returns an array of two strings

7) The charcomp output modifies the input into output by running a multidimensional fuzzy string comparison algorithm I wrote and wraps differences in "<em>" HTML tags that I write into the strings being compared.

This is really all that happens in the diffview library from a high level. Beyond this I would need to get into the code and go over it condition by condition or line by line.

Thanks,


Austin
________________________________________
From: prett...@googlegroups.com [prett...@googlegroups.com] on behalf of Rahul Raina [raina....@gmail.com]

Sent: Sunday, July 13, 2014 5:38 AM
To: prett...@googlegroups.com
Subject: Re: [Pretty Diff] xml order of nodes not c

Hi,
Austin:

--


You received this message because you are subscribed to the Google Groups "Pretty Diff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretty-diff...@googlegroups.com.
To post to this group, send email to prett...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/pretty-diff/423f2c72-b6d2-4e3c-90ad-8f39f1f18992%40googlegroups.com.

Cheney, Edward A SFC USARMY (US)

unread,
Jul 15, 2014, 5:32:47 PM7/15/14
to prett...@googlegroups.com
Rahul,

The "source" and "diff" properties are properties for the Pretty Diff application. The actual diffview.js library takes "baseTextLines" and "newTextLines". I updated the fiddle:

http://jsfiddle.net/cJ6b3/1/

Since the output is HTML it is pretty reliant on CSS for the diff report to be legible. The various APIs for Pretty Diff package the CSS into the output file so that you don't need a separate CSS file. You can take the CSS directly from: http://prettydiff.com/diffview.css


________________________________________
From: prett...@googlegroups.com [prett...@googlegroups.com] on behalf of Rahul Raina [raina....@gmail.com]

Sent: Tuesday, July 15, 2014 6:16 AM
To: prett...@googlegroups.com
Subject: [Pretty Diff] Re: xml order of nodes not c

Base Source

New Source

00

--


You received this message because you are subscribed to the Google Groups "Pretty Diff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretty-diff...@googlegroups.com.
To post to this group, send email to prett...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/pretty-diff/c05fc870-197b-4038-8d7a-7956492e3a46%40googlegroups.com.

Rahul Raina

unread,
Jul 16, 2014, 3:59:37 AM7/16/14
to prett...@googlegroups.com
Thanks a ton, This can get me going somewhere :)
Reply all
Reply to author
Forward
0 new messages