Manipulating HTML DOM using Julia

Hi, I am trying to manipulate the DOM elements(e.g. adding a parent node and changing hierarchy of some nodes) of a HTML document. I could parse the HTML using Gumbo.jl. However, I could not manipulate the DOM using that package. I looked into LightXML.jl and EzXML.jl. However, they were not really suited for parsing HTML with javascript inside script tags and had multiple parsing errors. Could someone please let me know if there are any other resources to manipulate HTML DOM in Julia (e.g. adding parent nodes, child nodes, changing tag names and changing the content of nodes).

I think I figured out how to manipulate the DOM using Gumbo.jl manually. However I am having difficulty getting to change the actual tree.

using Gumbo
import AbstractTrees
doc = parsehtml("""
<html>
    <head>
        <title>Title</title>
    </head>
    <body>
        <span>this is a span 1</span>
        <div>
            <span>this is a span 2</span>
        </div>
    </body>
</html>
""");

if i wanted to change the <span> to a <p>

for elem in AbstractTrees.PreOrderDFS(doc.root)
    if isa(elem, HTMLElement)
        if tag(elem) == :span
            elem = HTMLElement{:p}(elem.children,elem.parent,elem.attributes)
        end
    end
end

and this does not work

julia> doc
HTML Document:
<!DOCTYPE >
<HTML>
  <head>
    <title>
      Title
    </title>
  </head>
  <body>
    <span>
      this is a span 1
    </span>
    <div>
      <span>
        this is a span 2
      </span>
    </div>
  </body>
</HTML>

Could someone please let me know how to do this correctly.