XmlReader - I need to edit an element and produce a new one

前端 未结 5 2110
花落未央
花落未央 2020-12-20 15:54

I am overriding a method which has an XmlReader being passed in, I need to find a specific element, add an attribute and then either create a new XmlReader or just replace t

5条回答
  •  自闭症患者
    2020-12-20 16:46

    You can't easily do this with XmlReader - at least, not without reading the whole XML document in from the reader, futzing with it and then creating a new XmlReader from the result. That defeats a lot of the point of using XmlReader though - namely the ability to stream large documents.

    You could potentially derive from XmlReader, forwarding most method calls to the existing reader but intercepting them where appropriate to add extra attributes etc... but I suspect that code would be really quite complex and fragile.

提交回复
热议问题