Python - What does my XML contain?



I'm new to this whole Python-universe, but have decided to start out by learning how to handle open data-formats, primarily XML for starters.


I have encountered a problem where I cannot figure out how I get an overview of a parsed .XML-file.


The example I'm following would have me do this:



from xml.etree.ElementTree import parse
doc = parse('rt22.xml')

for bus in doc.findall('bus'):


This means parsing the .XML I have written myself, and then, in this example, start looking for an element with a certain name.


The example knows that there's something called "bus" in the XML-file, but now that I've found and parsed my own XML-file, I don't know what it contains.


If I just open it with a texteditor, I get to see this:



<TilOgFraflytninger>
<row>
<TilOgFraflytningId>1</TilOgFraflytningId>
<LejemaalId>1</LejemaalId>
<AfdId>1</AfdId>
<SelId>1</SelId>
<TilFlyttet>1954-08-01T00:00:00</TilFlyttet>
<FraFlyttet>2010-05-15T00:00:00</FraFlyttet>
</row>
<row>
<TilOgFraflytningId>2</TilOgFraflytningId>
<LejemaalId>1</LejemaalId>
<AfdId>1</AfdId>
<SelId>1</SelId>
<TilFlyttet>2010-06-15T00:00:00</TilFlyttet>
<FraFlyttet>2013-11-28T00:00:00</FraFlyttet>
</row>


But how would I get that information (that something is called "AfdId" etc.) without having to open the XML in a text editor?


No comments:

Post a Comment