XML: ignoring order or elems and attribs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koen
    Visitor
    • Oct 2011
    • 4

    XML: ignoring order or elems and attribs

    Is there way to compare XML so that the order of the elements or attributes does not matter.
    So
    <root>
    <elems1/>
    <elems2/>
    </root>
    is equal to
    <root>
    <elems2/>
    <elems1/>
    </root>
  • Aaron
    Team Scooter
    • Oct 2007
    • 16000

    #2
    If you are familiar with XSLT editing, you can alter our XML Sorted or Sorted and Tidied format to match and sort based on your current XML structure. It is possible the current implementation may meet your needs as well.

    http://www.scootersoftware.com/downl...oreformats_alt

    Once installed, the files are located in the Beyond Compare 3\Helpers directory.
    Aaron P Scooter Software

    Comment

    • koen
      Visitor
      • Oct 2011
      • 4

      #3
      improved sort?

      For my XML files, the provided sort did not make any changes. Strange
      I found a better one that first sorts the attributes in an element and then sorts the elements

      <xsl:template match="@* | node()">
      <xsl:copy>
      <xsl:apply-templates select="@*">
      <xsl:sort select="name()"/>
      </xsl:apply-templates>
      <xsl:apply-templates select="node()">
      <xsl:sort select="name()"/>
      </xsl:apply-templates>
      </xsl:copy>
      </xsl:template>

      It look like it should work for most XML files.
      See the attached stylesheet

      Comment

      • Vindhya
        Visitor
        • Jul 2012
        • 3

        #4
        For me also XML sorted and XML Sorted and Tidied didn't work even for simple XML files. I added a seperate thread to this forum asking that question(http://www.scootersoftware.com/vbull...ead.php?t=8851). But I didn't get any replies yet. Why it doesn't work?

        Comment

        • Aaron
          Team Scooter
          • Oct 2007
          • 16000

          #5
          Thanks for the sample conversion. It looks like that xslt works great for your files, but strips out any content between nodes (<a>content</a>) and removes any <!-- comments -->. Would you know of a way to preserve this information?
          Aaron P Scooter Software

          Comment

          • Aaron
            Team Scooter
            • Oct 2007
            • 16000

            #6
            Sorry for the delay. I have been comparing our current xslt results with koen's example to see if we can have a single, multipurpose xslt that works for a broad range of files. I am not familiar enough with the xslt format to make something like this quickly; our previous xslt conversions have been provided by helpful customers. In the meantime, if you are familiar with xslt, you can alter/edit the one the conversion process uses in the Beyond Compare 3\Helpers\HtmlTidy\ directory: XML_sorted.xslt
            Aaron P Scooter Software

            Comment

            Working...