Python XML editing library preserving formatting and comments

I need to make a few changes to existing XML files, while preserving the formatting and comments - all but the minor changes that I make should not be affected. I tried xml.etree and lxml.etree without success.

XML is generated by my IDE, but its editor has no functionality, so I need to make a few manual changes. I want to keep the formatting so that the differences are good and not pollute my story.

With a lot of python XML libraries, I thought I would ask here if someone had done something like this.

+6
source share
1 answer

How many and what changes do you need to make? It sounds to me as if you could be better off just using a standalone XML editor (Google only for them, there are many). Honestly, I'm a little surprised that your IDE does not have a suitable search and replacement for your needs. (Most of the ones I've seen even have regex tools for this.) If you really need to write a program to make changes to the XML, and you don't want to mess up the formatting and comments, your best bet is to open the XML as plain text file in Python and use its regex library ( import re ) to perform search and replace.

0
source

Source: https://habr.com/ru/post/891763/


All Articles