Hello,
I am new to cxml and need some assistance to get started.
Thanks to https://common-lisp.net/project/cxml/quickstart.html, it is fairly easy to read existing xml and write them back (almost) identical:
(defun parse-dom (file) (cxml:parse file (cxml-dom:make-dom-builder)))
(defun serialize-dom (file dom new-extension) (with-open-file (out (make-pathname :defaults file :type new-extension) :direction :output :if-exists :supersede :element-type '(unsigned-byte 8))
(write-sequence #(#xef #xbb #xbf) out) ;; byte order mask
(dom:map-document (cxml:make-octet-stream-sink out :encoding "utf-8") dom)))
(let ((file #p"some-file.xml")) (serialize-dom file (parse-dom file) "new-xml"))
with this, I can read a file and write it back. With
diff -uw some-file.xml some-file.new-xml
I can confirm that those files are (semantically) identical.
But how do I go further? As a start, I would like to remove elements and/or attributes while writing. From the docs, I seem to understand that this can be done using sinks. But I just can't figure how to create my custom sink to do the filtering. And three das googling did not reveal any examples/howtos/tutorials.
Can somebody provide an example how to create a custom sink and which methods can be specialized to do such filtering?
Thanx!