Sorted Attributes in XML.jl?


I saw the newly released XML.jl and I am really excited about it.

I wonder if it is possible to “enforce” attribute ordering? I have a case in which I want to produce and XML which is meant to be both human readable and machine input. Suppose I have an XML tag:

<point x=0 y=0 z=0/>

This nice because x y and z are ordered - the machine who reads it does not care about the order of course, but the human user who has to edit it, does. Currenly in XML.jl:

using XML
  Node Element <point x="0" z="0" y="0">

Which is not ordered, which makes the human user sad.

Is there any way to make it so that the order of input arguments into XML.Element is respected?

I do not care about performance, I much higher value the ordering of inputs, so even subpar performance (but generic) solutions I would appreciate at this stage :slight_smile:

Kind regards

The backing type for the attributes is a Dict which is inherently unordered. XML.jl/XML.jl at main · JuliaComputing/XML.jl · GitHub
Maybe the author would consider using OrderedCollections.OrderedDict instead?

Would it be possible for me to overload/extend it in some smart way so that I can use OrderedDicts?

No, it’s not a type parameter. Maybe if you made your own node type and if dispatches are written generically enough

1 Like

GitHub - andyferris/Dictionaries.jl: An alternative interface for dictionaries in Julia, for improved productivity and performance is a good ordered dictionary interface that could be proposed if you raise this issue with the author.


issue about preserving attribute order posted

1 Like

Thank you @jules for explaining

Thank you @jar1 for mentioning this library, I was only aware of OrderedDicts

Thank you @JeffreySarnoff for posting it on Github

Kind regards

FYI XML.jl v0.3.0 is now available in General, which uses OrderedDict as the internal representation of attributes and maintains attribute order.


Thank you so much!

I upgraded the package and it just worked out of the box