Skip to content

== method should be insensitive to attribute order #7

Closed
@MarkNahabedian

Description

@MarkNahabedian

Given that:

  • attribute order is not significant in XML,
  • the Node constructors in this package do not preserve attribute order;

the method of Base.==(::Node, ::Node) should compare attributes independent of their order in each element.

This works for me:

function node_equal(a::XML.Node, b::XML.Node)
    function attrs_equal(a1, a2)
        if a1 == nothing && a2 == nothing
            return true
        end
        if a1 == nothing || a2 == nothing
            return false
        end
        for key in union(keys(a1), keys(a2))
            if get(a1, key, nothing) != get(a2, key, nothing)
                return false
            end
        end
        return true
    end
    a.type == b.type &&
        a.tag == b.tag &&
        attrs_equal(a.attributes, b.attributes) &&
        a.children == b.children
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions