def graph_from_xml(
    filepath: str | Path,
    *,
    bidirectional: bool = False,
    simplify: bool = True,
    retain_all: bool = False,
    encoding: str = "utf-8",
) -> nx.MultiDiGraph:
    """
    Create a graph from data in an OSM XML file.

    Do not load an XML file previously generated by OSMnx: this use case is
    not supported and may not behave as expected. To save/load graphs to/from
    disk for later use in OSMnx, use the `io.save_graphml` and
    `io.load_graphml` functions instead.

    Use the `settings` module's `useful_tags_node` and `useful_tags_way`
    settings to configure which OSM node/way tags are added as graph node/edge
    attributes.

    Parameters
    ----------
    filepath
        Path to file containing OSM XML data.
    bidirectional
        If True, create bidirectional edges for one-way streets.
    simplify
        If True, simplify graph topology with the `simplify_graph` function.
    retain_all
        If True, return the entire graph even if it is not connected. If
        False, retain only the largest weakly connected component.
    encoding
        The OSM XML file's character encoding.

    Returns
    -------
    G
        The resulting MultiDiGraph.
    """
    # transmogrify file of OSM XML data into JSON
    response_jsons = [_osm_xml._overpass_json_from_xml(Path(filepath), encoding)]

    # create graph using this response JSON
    G = _create_graph(response_jsons, bidirectional)

    # keep only the largest weakly connected component if retain_all is False
    if not retain_all:
        G = truncate.largest_component(G, strongly=False)

    # simplify the graph topology as the last step
    if simplify:
        G = simplification.simplify_graph(G)

    msg = f"graph_from_xml returned graph with {len(G):,} nodes and {len(G.edges):,} edges"
    utils.log(msg, level=lg.INFO)
    return G

    Create a graph from data in an OSM XML file.

    Do not load an XML file previously generated by OSMnx: this use case is
    not supported and may not behave as expected. To save/load graphs to/from
    disk for later use in OSMnx, use the `io.save_graphml` and
    `io.load_graphml` functions instead.

    Use the `settings` module's `useful_tags_node` and `useful_tags_way`
    settings to configure which OSM node/way tags are added as graph node/edge
    attributes.

    Parameters
    ----------
    filepath
        Path to file containing OSM XML data.
    bidirectional
        If True, create bidirectional edges for one-way streets.
    simplify
        If True, simplify graph topology with the `simplify_graph` function.
    retain_all
        If True, return the entire graph even if it is not connected. If
        False, retain only the largest weakly connected component.
    encoding
        The OSM XML file's character encoding.

    Returns
    -------
    G
        The resulting MultiDiGraph.
    
osmnx/graph.py