The xml-conduit tutorial (the only one in existence, and perhaps the only Haskell XML library with a tutorial) shows how to create or read an XML document, but not how to modify one. The only way I am familiar with such operations is using lxml/elementtree (python), which only works through side-effect (that I'm aware of). I suspect a very different approach here.
Say that I have a simple document:
<html>
<head>
<title>My <b>Title</b></title>
</head>
<body>
<p>Paragraph 1.</p>
<p>Paragraph 2.</p>
</body>
</html>
How to:
- Modify the title?
- Delete the first paragraph in this document?
- Append the body of this document to the body of another document?
Feel free to propose and contribute a solution using other Haskell libraries. The community could use many more examples.
By reading the XML document and writing a new one, keeping the similarities you want but differing in the respects you desire.
Say you have a
document:: Document
. If you prefer record syntax over lenses, you might wind up with a solution that looks somewhat like the following. To be fair, refactoring it into small functions with descriptive names can make somewhat more readable. Alternatively, you can use lenses, a library of small, generic functions with undescript names that are useful for exactly this kind of DOM tree manipulations.