XML: how to parse, find elements, replace their contents, and store in a new file?

As per the title, I am looking for a way to modify an XML file through XPath. To avoid the X/Y problem, let me explain why: it seems too much work to employ a SAX parser and just store hierarchical state until I find a match, and then modify the element and store to a new structure. But I am open to be proven wrong.

I scanned quickly several libraries around here but save for Exoml – which I’ll dig into – everything else seems to either not support this scenario, or require more effort than I am willing to put into this toy problem. Still, I really want to get it done so I am also open for suggestions that aren’t quick or simple as well.

Anybody did something like that?

1 Like

It seems SweetXml has transform_by/2 which I’ll evaluate as well.

1 Like

This article offers a comprehensive list of ways in which yo can parse XML. For your specific use case (XPath) yo can you :xmerl_xpath to achieve your goal of easily reading an XML file.

I make no claims as to how fast/slow or memory efficient the solutions on the article are, only that from what I have seen, they seem to make it easy to read XML files.

1 Like

Not even remotely conclusive. ^.^

It’s missing Meeseeks entirely for one thing!