Symantec Access Management

Expand all | Collapse all

XML Canonical Sort

  • 1.  XML Canonical Sort

    Posted 10-25-2017 02:17 PM

    Team,

     

    Have you been able to identify an XML Canonical Sort utility that allows flexibility with sorting various XML files the way you wish?

     

    I have reviewed the following:

     

    1) NotePad++ with the compare option (fine for text files but limited value for XML)

     

    2) Beyond Compare with the FileFormat of XML and XML Sort is better;  identifies from 1600+ deltas to 196 deltas.

     

    3) Altova XMLSpy/DeltaDog offer quite a bit of features, but will need to invest more time to identify flexibility.

     

     

    Specifically, I am looking for the following:

     

     

     

    I have had better luck with using the Linux package:   xmllint  with a few switches.

     

     

    $ xmllint --exc-c14n ime-roles-task-01.xml > 1.xml
    $ xmllint --exc-c14n ime-roles-task-02.xml > 2.xml
    $ diff 1.xml 2.xml

     

    Then copy these new files to Beyond compare with the XML Sort File Format.

     

    1) Before BC XML Sort File Format (non-sorted):   1600+ deltas

    2) With BC XML Sort File Format:    190+ deltas  (better)

    3) With xmllint pre-sort, then with BC XML Sort File Format:   60+ deltas   [But order with sections is mixed]

     

     

    Thoughts?

     

    Edit 10/30/2017 -    Using Altova XMLSpy or Oxygen XML Editor, it is fairly easy to load an XML file, then switch to GRID mode.   In GRID mode, you can select alpha/numeric ascending or descending sorts on a column.    

     

    The challenge for XML sorting, within an "attribute" (item #6 above in the table), this is a block of information.

     

    A better approach may be to create a custom XSLT "stylesheet" file, to be used with the XML file.   To sort the way you wish, even for data that is within an element.   Many "templates" can be applied within this stylesheet, to manage sorting by alphabetically or via the priority number(s) within an attribute's body.

     

    Example:   

     

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates>
    <xsl:sort select="(@name, name())[1]"/>
    </xsl:apply-templates>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

     

     

     

     

     

    Cheers,

     

    A.



  • 2.  Re: XML Canonical Sort

    Posted 10-30-2017 06:14 AM

    Hi Alan,

    I'm using Brackets and then I have download its plugin to sort & beautify.

    It is easy and also i check (if you need) any errors inside the xml.

     

    Cheers,

    Pasquale