Reading XML and Printing Data in Word or PDF with Python

0

Good evening, gentlemen. I would like to ask the help of university students to read this XML file below and print the values in Word or PDF.

<?xml version="1.0" encoding="UTF-8"?>

-<profiles xsi:noNamespaceSchemaLocation="schemas/6.11.2/exercise/profiles.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" model-version="4.8.2">


-<profile time-control="false" supervision="false" password="red" name="AZUL">


-<rights>

<readonly/>


-<readwrite>

<side id="1"/>

<side id="115143"/>

</readwrite>

</rights>

</profile>


-<profile time-control="true" supervision="true" password="" name="DIREx">


-<rights>

<readonly/>


-<readwrite>

<side id="3"/>

<side id="1"/>

<side id="115143"/>

<formation id="1458"/>

<formation id="7309"/>

<formation id="8158"/>

<formation id="8504"/>

<formation id="8555"/>

<formation id="9143"/>

<formation id="12143"/>

<formation id="12163"/>

<formation id="12183"/>

<formation id="12203"/>

<formation id="12223"/>

<formation id="12257"/>

<formation id="12757"/>

<formation id="44988"/>

<automat id="13930"/>

<automat id="13936"/>

<automat id="88064"/>

<automat id="88129"/>

<automat id="88189"/>

<automat id="88245"/>

<automat id="88280"/>

<automat id="88335"/>

</readwrite>

</rights>

</profile>


-<profile time-control="true" supervision="true" password="sommer" name="SUPERVISOR">


-<rights>

<readonly/>


-<readwrite>

<side id="1"/>

<side id="3"/>

<side id="115143"/>

<formation id="1458"/>

<formation id="7309"/>

<formation id="8158"/>

<formation id="8504"/>

<formation id="8555"/>

<formation id="9143"/>

<formation id="12143"/>

<formation id="12163"/>

<formation id="12183"/>

<formation id="12203"/>

<formation id="12223"/>

<formation id="12257"/>

<formation id="12757"/>

<formation id="44988"/>

<automat id="13930"/>

<automat id="13936"/>

<automat id="88064"/>

<automat id="88129"/>

<automat id="88189"/>

<automat id="88245"/>

<automat id="88280"/>

<automat id="88335"/>

</readwrite>

</rights>

</profile>


-<profile time-control="false" supervision="false" password="blue" name="VERMELHO">


-<rights>

<readonly/>


-<readwrite>

<side id="3"/>

<side id="115143"/>

</readwrite>

</rights>

</profile>

</profiles>

I need to remove only the values of the name and password lines in order, from all tags.

Thank you.

    
asked by anonymous 10.10.2018 / 21:49

1 answer

0

Using the excellent lxml library:

>>> doc = lxml.etree.parse(seu_arquivo_xml)
>>> print(doc.xpath('//@name')) #localiza elementos com atributo 'name'
['AZUL', 'DIREx', 'SUPERVISOR', 'VERMELHO']
>>> print(doc.xpath('//@password')) #localiza elementos com atributo 'password'
['red', '', 'sommer', 'blue']
    
10.10.2018 / 22:32