How to modify XML as text in lxml



I have an XML file generated by an IDE; however, it unfortunately outputs code with newlines as BRs and seems to randomly decide where to place newlines. Example:



if test = true
foo;
bar;
endif


becomes the following XTML within an XML file:



<body>
<p>if test = true<br /> foo;<br /> bar;<br />endif
</p>
</body>


I am trying to make a pre-processor for these files in python using lxml to make it easier to version control them. However, I cannot figure out to modify the XML as text so that I can place each BR on it's own line like the following:



<body>
<p>if test = true
<br /> foo;
<br /> bar;
<br />endif
</p>
</body>


How does one edit the xml as text, or failing that, is there another way to get the results like above?


No comments:

Post a Comment