[ANN] Announcing XML.jl

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.

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:

<setdrawmode mode="full" />

What I have is:

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 Attributeobject similar to the Element one?

Thank you

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

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

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

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!

1 Like

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

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.

3 Likes

This is amazing! Except now I have investigate whether to rewrite PPTX.jl and a bunch of our internal XML tools :slight_smile:

3 Likes

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

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

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

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

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.

1 Like

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:

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

Which works :slight_smile:

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

Kind regards