Creating an XML Document

How can I programmatically build an XML document? (the object, not the text)

There’s XML.parse that creates one from a string, but I can’t find anything else. XML.build (what I thought I would use) returns a string. Am I supposed to build it, get the string and then parse it? :grimacing:

And once I have it, how can I modify it?

1 Like

nokogiri

https://github.com/sparklemotion/nokogiri/wiki/Cheat-sheet#creating-and-working-with-documents

Nokogiri is a Ruby gem. It doesn’t work in Crystal.
Looks like Nokogiri requires creating a document by parsing an XML source (which may be empty), and then you can mutate that document.

Unfortunately, Crystal’s stdlib doesn’t really provide any APIs for mutating an XML document.
See XML: improve the DOM interface · Issue #15915 · crystal-lang/crystal · GitHub

1 Like