Module parse
source code
Take an SABX XML tree and turn it into objects.
parse_tree is the main entry point for parsing XML.
When you pass it an XML tree of SABX data, it returns a dictionary of
information corresponding to the structure of an SABX file. It's
returned as a dict
because I generally use this to read an
SABX file, modify it, then run it through a Jinja2 template for output.
Jinja2 takes a dictionary to pass to the template as it's template
data.
Here's a somewhat graphical representation of the data that you get
back from parse_tree.
-
SABX -
dict
-
uuid
-
version
-
zip_prefix
-
desc
-
ride_type
-
title
-
description
-
terrain
-
photos - PhotoSet
-
park_list and park_dict -
list
and dict
-
turn_list and turn_dict -
list
and dict
-
seg_list and seg_dict -
list
and dict
-
stop_list and stop_dict -
list
and dict
-
poi_list and poi_dict -
list
and dict
-
ride_list and ride_dict -
list
and dict
-
contains Ride
-
id
-
description
-
parking id
-
turns -
list
-
segments -
list
-
history -
list
|
Photo
A Photo object holds the information for an
"a" HTML element that links to photos of the ride.
|
|
PhotoSet
A PhotoSet object holds information about a cover
photo for the rideset and links to additional photos of the ride.
|
|
HistoryUpdate
A HistoryUpdate object holds the information for a
single update to the SABX file.
|
|
__package__ = ' sabx10.oxm '
|
Take the Element for a photos element and turn it into a
list of Photo objects.
- Parameters:
xml_photos (Element ) - Element for the PhotoSet element
- Returns:
list of Photo
list of Photo objects
|
Parse the photos element in the given Element tree.
- Parameters:
xml_tree (Element or ElementTree ) - root of Element tree that has photos
- Returns:
PhotoSet
- a
PhotoSet object or None
|
Parse the history element in the given Element tree.
- Parameters:
xml_tree (Element or ElementTree ) - root of Element tree that has history in it
- Returns:
list of HistoryUpdate
List of HistoryUpdates
|
Parse all of the simple root elements in an SABX file.
The simple root elements are:
-
uuid
-
version
-
zip_prefix
-
description
-
ride_type
-
title
-
description
-
terrain
- Parameters:
xml_tree (Element or ElementTree ) - root of Element tree that has SABX data
- Returns:
dict
dict of root elements
|
Parse a whole SABX file.
- Parameters:
xml_tree (Element or ElementTree ) - root of Element tree that has SABX data
- Returns:
dict
dict of parsed SABX data
|