Skip to content

Sorting nodes with mixed content can break the content #11

@DanielRose

Description

@DanielRose

XML elements can have several different kinds of child nodes. According to the documentation, that includes Element, Text, Comment, ProcessingInstruction, CDATA, and EntityReference. Always sorting the child nodes can break the content, since the order can be important. For example:

<text>Click on <url target="/home" /> to return to the home page.</text>

Simply sorting this results in

<text>Click on  to return to the home page.<url target="/home" /></text>

which is most probably not wanted.

Thus, only when the child nodes are all elements themselves should sorting occur.

However, this is very strict, so comments should be allowed as well. Since there is no sure way to tell where the comments should be sorted (they may belong to the element above, below, at the start or end of all children or only of the same type, ...), the easiest way is to sort them as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions