def parse_gpx(gpx_element, gpx_extensions_parser=None,
                   metadata_extensions_parser=None,
                   waypoint_extensions_parser=None,
                   route_extensions_parser=None,
                   track_extensions_parser=None,
                   segment_extensions_parser=None,
                   gpxns=None):
    """Parse a GPX file into a GpxModel.

    Args:
        gpx_element: gpx_element: The root <gpx> element of an XML document
            containing a version attribute. GPX versions 1.1 is supported.

        gpx_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        metadata_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.

        waypoint_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.

        route_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        track_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        segment_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.


    Returns:
        A GpxModel representing the data from the supplies xml.

    Raises:
        ValueError: The supplied XML could not be parsed as GPX.
    """
    gpxns = gpxns if gpxns is not None else determine_gpx_namespace(gpx_element)

    if gpx_element.tag != gpxns+'gpx':
        raise ValueError("No gpx root element")

    creator = gpx_element.attrib['creator']
    version = gpx_element.attrib['version']

    if not version.startswith('1.1'):
        raise ValueError("Not a GPX 1.1 file")

    metadata_element = gpx_element.find(gpxns+'metadata')
    metadata = nullable(parse_metadata)(metadata_element, gpxns)

    waypoint_elements = gpx_element.findall(gpxns+'wpt')
    waypoints = [parse_waypoint(waypoint_element, gpxns) for waypoint_element in waypoint_elements]

    route_elements = gpx_element.findall(gpxns+'rte')
    routes = [parse_route(route_element, gpxns) for route_element in route_elements]

    track_elements = gpx_element.findall(gpxns+'trk')
    tracks = [parse_track(track_element, gpxns) for track_element in track_elements]

    extensions_element = gpx_element.find(gpxns+'extensions')
    extensions = nullable(parse_gpx_extensions)(extensions_element, gpxns)

    gpx_model = GpxModel(creator, metadata, waypoints, routes, tracks,
                         extensions)

    return gpx_model
def parse_gpx ( gpx_element , gpx_extensions_parser = None , metadata_extensions_parser = None , waypoint_extensions_parser = None , route_extensions_parser = None , track_extensions_parser = None , segment_extensions_parser = None , gpxns = None ) : gpxns = gpxns if gpxns is not None else determine_gpx_namespace ( gpx_element ) if gpx_element . tag != gpxns + 'gpx' : raise ValueError ( "No gpx root element" ) creator = gpx_element . attrib [ 'creator' ] version = gpx_element . attrib [ 'version' ] if not version . startswith ( '1.1' ) : raise ValueError ( "Not a GPX 1.1 file" ) metadata_element = gpx_element . find ( gpxns + 'metadata' ) metadata = nullable ( parse_metadata ) ( metadata_element , gpxns ) waypoint_elements = gpx_element . findall ( gpxns + 'wpt' ) waypoints = [ parse_waypoint ( waypoint_element , gpxns ) for waypoint_element in waypoint_elements ] route_elements = gpx_element . findall ( gpxns + 'rte' ) routes = [ parse_route ( route_element , gpxns ) for route_element in route_elements ] track_elements = gpx_element . findall ( gpxns + 'trk' ) tracks = [ parse_track ( track_element , gpxns ) for track_element in track_elements ] extensions_element = gpx_element . find ( gpxns + 'extensions' ) extensions = nullable ( parse_gpx_extensions ) ( extensions_element , gpxns ) gpx_model = GpxModel ( creator , metadata , waypoints , routes , tracks , extensions ) return gpx_model
Parse a GPX file into a GpxModel.

    Args:
        gpx_element: gpx_element: The root <gpx> element of an XML document
            containing a version attribute. GPX versions 1.1 is supported.

        gpx_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        metadata_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.

        waypoint_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.

        route_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        track_extensions_parser: An optional callable which accepts an Element
            with the 'extensions' tag and returns a list of model objects
            representing the extensions. If not specified, extensions are
            ignored.

        segment_extensions_parser: An optional callable which accepts an
            Element with the 'extensions' tag and returns a list of model
            objects representing the extensions. If not specified, extensions
            are ignored.


    Returns:
        A GpxModel representing the data from the supplies xml.

    Raises:
        ValueError: The supplied XML could not be parsed as GPX.