Skip to content

Instantly share code, notes, and snippets.

@poliarush
Created February 9, 2015 21:41
Show Gist options
  • Save poliarush/47a45ccdad02b10b61ea to your computer and use it in GitHub Desktop.
Save poliarush/47a45ccdad02b10b61ea to your computer and use it in GitHub Desktop.
xml parsing
ApplicationState = None [ObjectifiedElement]
* xsi:noNamespaceSchemaLocation = 'ApplicationState.xsd'
appState = 'PRE_RACE' [StringElement]
eventId = 3625 [IntElement]
trackId = 713 [IntElement]
NextEventId = 3621 [IntElement]
PastEventId = 3627 [IntElement]
PRE_RACE
3625
713
xml = """
<ApplicationState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ApplicationState.xsd">
<appState>PRE_RACE</appState>
<eventId>3625</eventId>
<trackId>713</trackId>
<NextEventId>3621</NextEventId>
<PastEventId>3627</PastEventId>
</ApplicationState>
"""
from lxml import objectify
root = objectify.fromstring(xml)
print(objectify.dump(root))
print root.appState
print root.eventId
print root.trackId
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment