quick-xml icon indicating copy to clipboard operation
quick-xml copied to clipboard

Modify Document in-place

Open gmitchel-snek opened this issue 10 months ago • 3 comments

I was looking at the docs about the writer:

"A XML writer. Can be nested with readers if you want to transform XMLs. Especially for nested XML elements, the user must keep track where (how deep) in the XML document the current event is located."

I was looking and there is no documentation or an example regarding this. Is there an example that can show this happening?

gmitchel-snek avatar Feb 19 '25 23:02 gmitchel-snek

We do not have much examples of writing yet. Basically, the example from Writer is the one example of writing which also shows how to transform document (it is not "in place", but "streaming"). In that example you can see that we just check the tag name to see if we need to replace it. In case of document like

<this_tag>
  <this_tag>
    <this_tag>
    </this_tag>
  </this_tag>
</this_tag>

we will replace all three of them, while you may want to replace, say, only most nested. So you additionally should keep track the nesting level, which is increasing before procession of each Start event and decreasing after processing of the End event.

Mingun avatar Feb 20 '25 08:02 Mingun

Ah ok, so we can't really use this method to modify a document in place really, we must make a new file?

gmitchel-snek avatar Feb 20 '25 17:02 gmitchel-snek

Yes, you need to write new document

Mingun avatar Feb 20 '25 20:02 Mingun