# Sorted Attributes in XML.jl?

**URL:** <https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168>\
**Category:** General Usage\
**Created:** [June 11, 2023, 6:39am UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168 "2023-06-11T06:39:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [June 11, 2023, 6:39am UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/1 "2023-06-11T06:39:06Z")

</div>

Hello!

I saw the newly released [XML.jl](https://github.com/JuliaComputing/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:

```xml
<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:

```julia
using XML
  XML.Element("point",x=0,y=0,z=0)
  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 🙂

Kind regards

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 11, 2023, 2:14pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/2 "2023-06-11T14:14:10Z")

</div>

The backing type for the attributes is a `Dict` which is inherently unordered. [XML.jl/XML.jl at main · JuliaComputing/XML.jl · GitHub](https://github.com/JuliaComputing/XML.jl/blob/main/src/XML.jl#L131)  
Maybe the author would consider using `OrderedCollections.OrderedDict` instead?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [June 11, 2023, 3:42pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/3 "2023-06-11T15:42:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 11, 2023, 3:46pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/4 "2023-06-11T15:46:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [June 11, 2023, 5:19pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/5 "2023-06-11T17:19:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [June 11, 2023, 7:59pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/6 "2023-06-11T19:59:29Z")

</div>

issue about [preserving attribute order](https://github.com/JuliaComputing/XML.jl/issues/14) posted

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [June 11, 2023, 8:13pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/7 "2023-06-11T20:13:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joshday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshday/32/368_2.png) [@joshday](https://discourse.julialang.org/u/joshday)\
**Post date:** [June 14, 2023, 1:49pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/8 "2023-06-14T13:49:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [June 14, 2023, 7:59pm UTC](https://discourse.julialang.org/t/sorted-attributes-in-xml-jl/100168/9 "2023-06-14T19:59:54Z")

</div>

Thank you so much!

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