Compare XML snippets?

后端 未结 10 894
名媛妹妹
名媛妹妹 2020-11-30 03:42

Building on another SO question, how can one check whether two well-formed XML snippets are semantically equal. All I need is \"equal\" or not, since I\'m using this for un

10条回答
  •  执笔经年
    2020-11-30 04:31

    If you take a DOM approach, you can traverse the two trees simultaneously while comparing nodes (node type, text, attributes) as you go.

    A recursive solution will be the most elegant - just short-circuit further comparison once a pair of nodes are not "equal" or once you detect a leaf in one tree when it's a branch in another, etc.

提交回复
热议问题