Say I have xml like this (the real one is more complicated):
<a>
<b>
<c replace="alpha" />
</b>
<d>
<c replace="beta"></c>
</d>
</a>
I've parsed this with BeautifulSoup (lxml) since I can't use regex. Now I'm replacing the <c>
with a string containing new valid xml that depends on the attribute. This isn't all that hard.
But I want to do it without parsing the new xml with BeautifulSoup. The reason is that I'm just going to prettify it right after. There are quite some tags being replaced by significant amounts of xml. It's not very performant parsing and then prettifying everything.
Is there something like a LiteralXmlPleaseDontParseThisTnx
node? (I can't find it, they must have called it something else, and there are too many unrelated hits for 'raw html', 'unparsed html', 'literal hmtl'...).
Alternatively, is there a way to prettify the above xml and then insert the new xml in that as plain text (without making assumptions about the xml beyond being valid)?