# \[ANN\] Announcing XML.jl

**URL:** <https://discourse.julialang.org/t/ann-announcing-xml-jl/99781>\
**Category:** Package Announcements\
**Tags:** xml\
**Created:** [June 2, 2023, 5:15pm UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781 "2023-06-02T17:15:03Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [June 3, 2023, 6:35pm UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/21 "2023-06-03T18:35:30Z")

</div>

Yeah, this is more like thousands of lines and polygons of multiple (color) categories, some needing transform matrices to get the right coord values… it was fine with XML.jl just way more work than I would like.

@fattender guess I assumed you were getting GeometryBasics.jl objects but I don’t really know Makie internals.

---

<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 4, 2023, 12:36am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/22 "2023-06-04T00:36:42Z")

</div>

I am trying to give this a go, but I am stuck at a very simple stage. I cannot figure out how to write a statement such as:

```julia
<setdrawmode mode="full" />

```

What I have is:

```julia
using XML: Document, Element, Declaration, Comment, CData, DTD, ProcessingInstruction, Text, escape, unescape

e = Element("setdrawmode","mode=full")

julia> XML.write(e)
"<setdrawmode>mode=full</setdrawmode>"

```

Which I know is equivalent to the first sentence, just a difference in the style. I have two questions:

1. Can I get the style from above, i.e. a closing “/\>” instead of repeat statement?
2. Instead of using “mode=full”, is their a more robust way to do this for example through an `Attribute`object similar to the `Element` one?

Thank you

---

<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 4, 2023, 1:10am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/23 "2023-06-04T01:10:25Z")

</div>

Those two things are actually not equivalent. I think you’re looking for this:

```julia
julia> XML.Element("setdrawmode", mode="full")
Node Element <setdrawmode mode="full">

julia> XML.write(ans)
"<setdrawmode mode=\"full\"/>"

```

---

<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 4, 2023, 1:14am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/24 "2023-06-04T01:14:54Z")

</div>

Amazing, I love that syntax.

EDIT: And you are right they are not the same since it is just text between tags and not an actual attribute, my bad - thanks for clarifying

Thank you!

---

<div class="post-metadata">

**Author:** ![Diego\_Javier\_Zea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diego_javier_zea/32/1858_2.png) [@Diego\_Javier\_Zea](https://discourse.julialang.org/u/Diego_Javier_Zea)\
**Post date:** [June 4, 2023, 11:26am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/25 "2023-06-04T11:26:07Z")

</div>

EzXML and LightXML are using the XML2 jll package, so that not should be a problem for secure computing environments. Am I correct?

---

<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 4, 2023, 11:34am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/26 "2023-06-04T11:34:49Z")

</div>

Having Julia approved/installed is not the same thing as having Julia + all packages approved. A secure environment would not let you reach out to the internet to update the General registry, download packages, etc. A JLL is still an external dependency, it’s just that Pkg makes it super easy to install.

Edit: To further clarify, I’ve worked with several customers who had no problem moving text files (Julia code) into their environment, but moving in an executable binary would require an approval process. This is the situation I am describing.

---

<div class="post-metadata">

**Author:** ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)\
**Post date:** [June 5, 2023, 8:10am UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/27 "2023-06-05T08:10:58Z")

</div>

This is amazing! Except now I have investigate whether to rewrite [PPTX.jl](https://github.com/ASML-Labs/PPTX.jl) and a bunch of our internal XML tools 🙂

---

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [June 6, 2023, 2:11pm UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/28 "2023-06-06T14:11:12Z")

</div>

I noticed that the `parse` in XML.jl has a different order of argument compared to `Base.parse`:

> <https://github.com/JuliaComputing/XML.jl/blob/dad503b9c062321a8d8cc27e259402a2daa40942/src/XML.jl#L268>

It’s not a big issue but slightly confusing when I attempted to replace the EzXML codes.

Is it useful to define more utilities for searching? For example

```julia
function Base.findall(xpath::AbstractString, nodes::Vector{Node})
   findall(x -> tag(x) == xpath, nodes)
end

function Base.findfirst(xpath::AbstractString, nodes::Vector{Node})
   findfirst(x -> tag(x) == xpath, nodes)
end

```

In EzXML, these are provided via Xpath query

> <https://github.com/JuliaIO/EzXML.jl/blob/a0025a7d801ec0cd6e74633de6ff2bd04e568696/docs/src/reference.md?plain=1#L169>

In Base, `findall` returns indices while in EzXML it returns elements.

---

<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 6, 2023, 8:00pm UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/29 "2023-06-06T20:00:54Z")

</div>

> [@henry2004y](#):
>
> I noticed that the `parse` in XML.jl has a different order of argument compared to `Base.parse`:

Actually I put both orderings in there (it’s one of those things I always get backwards…), but a typo is making the line you highlighted not work. I’ll get it fixed ASAP.

Yes, searching utilities would be good to have, although it’s pretty easy to write fast ones yourself that use `LazyNode`. I don’t have a lot of experience with XPath myself, but I’d certainly review some PRs.

---

<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 9, 2023, 7:47pm UTC](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781/30 "2023-06-09T19:47:16Z")

</div>

How would I add an attribute tot the element after it has been made? Any syntax like this:

`setdrawmode["mk"] = "0"`

EDIT: had a chat with Bing AI and was told:

```julia
setdrawmode.attributes["mk"] = "0"

```

Which works 🙂

Now is there any way to control the “ordering” of attributes inside elements?

Kind regards

[Previous page](https://discourse.julialang.org/t/ann-announcing-xml-jl/99781.md?page=1)
