MCPcopy Index your code
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / export_to_xml

Function export_to_xml

scrapegraphai/utils/data_export.py:47–66  ·  view source on GitHub ↗

Export data to an XML file. :param data: List of dictionaries containing the data to export :param filename: Name of the file to save the XML data :param root_element: Name of the root element in the XML structure

(
    data: List[Dict[str, Any]], filename: str, root_element: str = "data"
)

Source from the content-addressed store, hash-verified

45
46
47def export_to_xml(
48 data: List[Dict[str, Any]], filename: str, root_element: str = "data"
49) -> None:
50 """
51 Export data to an XML file.
52
53 :param data: List of dictionaries containing the data to export
54 :param filename: Name of the file to save the XML data
55 :param root_element: Name of the root element in the XML structure
56 """
57 root = ET.Element(root_element)
58 for item in data:
59 element = ET.SubElement(root, "item")
60 for key, value in item.items():
61 sub_element = ET.SubElement(element, key)
62 sub_element.text = str(value)
63
64 tree = ET.ElementTree(root)
65 tree.write(filename, encoding="utf-8", xml_declaration=True)
66 logger.info("Data exported to %s", filename)

Callers

nothing calls this directly

Calls 1

infoMethod · 0.45

Tested by

no test coverage detected