0

I have various XML schemas with lots of global elements that look like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="B">
        ...
    </xs:element>
    <xs:element name="C">
        ...
    </xs:element>
    <xs:element name="X">
        ...
    </xs:element>
    <xs:element name="F">
        ...
    </xs:element>
    <xs:element name="A">
        ...
    </xs:element>
</xs:schema>

Is there a free tool that can sort the elements alphabetically based on their names? This way it would be easier to compare and merge schemas. The result should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="A">
        ...
    </xs:element>
    <xs:element name="B">
        ...
    </xs:element>
    <xs:element name="C">
        ...
    </xs:element>
    <xs:element name="F">
        ...
    </xs:element>
    <xs:element name="X">
        ...
    </xs:element>
</xs:schema>
4

2 回答 2

0

One simple approach is to write an XSLT stylesheet to perform a near-identity transform on the schema document, with a sort on the appropriate apply-templates. There are numerous free XSLT implementations.

于 2013-07-02T15:31:20.340 回答
0

Another way of doing this came to my mind:

Import the XML via DOM, rearrange the nodes under the root node then write it back to a XML file.

于 2013-07-08T14:01:28.430 回答