简体   繁体   中英

compare xml through java and present it like a diff tool

I need to write a logic in java that

  1. Takes 2 versions of xmls like v1.xml & V2.xml
  2. Outputs the differences between the 2 xmls
  3. Displays them on a webpage just like any diff tool, like winmerge would display.
    • Removed lines - Highlighted in a unique color
    • Added lines - Highlighted in a unique color
    • Changed lines - Highlighted in a unique color

What is the best way to achieve this.

Thanks !

您可以使用XMLUnit来满足大多数需求。

Writing an XML parser from scratch is a bad idea if that is what you mean. It sounds really easy at first, but then quickly becomes a nightmare, trust me. I highly recommend taking advantage of existing tools.

http://www.roseindia.net/opensource/xmldiff.php lists several tools, inlcuding 3DM, diffmk, diffxml, VMTools , X-Diff , and XMLUnit . If you do have to write your own parser, you might want to at least look at the code from these projects for ideas. However, it takes much less time and effort to just give them credit and use their tools than to rewrite them yourself. I haven't used any of these tools, so buyer beware.

See also Tool or library for comparing xml files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM