Open source command line tool for Linux to diff XML files ignoring element order

后端 未结 6 1534
走了就别回头了
走了就别回头了 2021-02-04 09:57

Is there an open source command-line tool (for Linux) to diff XML files which ignores the element order?

Example input file a.xml:



        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 10:48

    From your example, it looks like you only care about re-ordering elements within elements, but not reordering elements themselves. If so, then (as a previous respondent said) you need to use sort, but on the elements, not the elements nor the attributes.

    Many would find it confusing to have XML elements named "tag" and/or "attr", since those are terms with specific meanings already in XML -- possibly that contributed to trying to sort by "@*" instead of sorting elements?

    If your structure is really just like your example, a much more "XML-ish" representation would be:

    
    
    
    

    Much more compact, avoids the terminology conflict, and makes the attributes be order-independent by definition -- which means any off-the-shelf XML diff utility will get the effect it seems you want, or you could just convert to canonical XML and use regular diff.

提交回复
热议问题