How to compare XML files

后端 未结 5 1733
遇见更好的自我
遇见更好的自我 2021-02-19 11:44

I have two XML files (XSD) which are generated by some tool.
The tool doesn\'t preserve the order of elements so although the content is equal comparing it as text will resu

5条回答
  •  遥遥无期
    2021-02-19 12:31

    For what it's worth, I have created a java tool (or kotlin actually) for effecient and configurable canonicalization of xml files.

    It will always:

    • Sort nodes and attributes by name.
    • Remove namespaces (yes - it could - hypothetically - be a problem).
    • Prettyprint the result.

    In addition you can tell it to:

    • Remove a given list of node names - maybe you do not want to know that the value of a piece of metadata - say has changed.
    • Sort a given list of collections in the context of the parent - maybe you do not care that the order of entries in has changed.

    It uses XSLT and does all the above efficiently using chaining.

    Limitations

    It does support sorting nested lists - sorting innermost lists before outer. But it cannot reliably sort arbitrary levels of recursively nested lists.

    If you have such needs you can - after having used this tool - compare the sorted byte arrays of the results. they will be equal if only list sorting issues remain.

    Where to get it

    You can get it here: XMLNormalize

提交回复
热议问题