A
A
Anton2018-08-14 07:36:52
Python
Anton, 2018-08-14 07:36:52

How to align XML structure?

How to align XML text structure? That is, there is XML text in this form:

<?xml version="1.0" ?>    <message>        <report>            <station ID="100" Name="main"/>                                                         <parameter VAR=A1>     100      </parameter>            <parameter VAR=A2> 200 </parameter>   </report> </message>

Whether prompt it is possible to it by means of the Python, to give a normal kind? Something like this:
<?xml version="1.0" ?>    
<message>        
<report>            
<station ID="100" Name="main"/>                                                     
<parameter VAR=A1> 
100      
</parameter>            
<parameter VAR=A2> 
200 
</parameter> 
</report> 
</message>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Yarkov, 2018-08-14
@8toni8

https://pypi.org/project/xmlformatter/

L
lega, 2018-08-14
@lega

s.replace('>', '>\n')

A
Andrey Salnikov, 2018-08-14
@Shshzik

from xml.dom import minidom

pretty = minidom.parseString('str').toprettyxml()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question