

def fromxml(source, *args, **kwargs):
    "\n    Extract data from an XML file. E.g.::\n\n        >>> import petl as etl\n        >>> # setup a file to demonstrate with\n        ... d = '''<table>\n        ...     <tr>\n        ...         <td>foo</td><td>bar</td>\n        ...     </tr>\n        ...     <tr>\n        ...         <td>a</td><td>1</td>\n        ...     </tr>\n        ...     <tr>\n        ...         <td>b</td><td>2</td>\n        ...     </tr>\n        ...     <tr>\n        ...         <td>c</td><td>2</td>\n        ...     </tr>\n        ... </table>'''\n        >>> with open('example1.xml', 'w') as f:\n        ...     f.write(d)\n        ...\n        212\n        >>> table1 = etl.fromxml('example1.xml', 'tr', 'td')\n        >>> table1\n        +-----+-----+\n        | foo | bar |\n        +=====+=====+\n        | 'a' | '1' |\n        +-----+-----+\n        | 'b' | '2' |\n        +-----+-----+\n        | 'c' | '2' |\n        +-----+-----+\n\n\n    If the data values are stored in an attribute, provide the attribute\n    name as an extra positional argument::\n\n        >>> d = '''<table>\n        ...     <tr>\n        ...         <td v='foo'/><td v='bar'/>\n        ...     </tr>\n        ...     <tr>\n        ...         <td v='a'/><td v='1'/>\n        ...     </tr>\n        ...     <tr>\n        ...         <td v='b'/><td v='2'/>\n        ...     </tr>\n        ...     <tr>\n        ...         <td v='c'/><td v='2'/>\n        ...     </tr>\n        ... </table>'''\n        >>> with open('example2.xml', 'w') as f:\n        ...     f.write(d)\n        ...\n        220\n        >>> table2 = etl.fromxml('example2.xml', 'tr', 'td', 'v')\n        >>> table2\n        +-----+-----+\n        | foo | bar |\n        +=====+=====+\n        | 'a' | '1' |\n        +-----+-----+\n        | 'b' | '2' |\n        +-----+-----+\n        | 'c' | '2' |\n        +-----+-----+\n\n    Data values can also be extracted by providing a mapping of field\n    names to element paths::\n\n        >>> d = '''<table>\n        ...     <row>\n        ...         <foo>a</foo><baz><bar v='1'/><bar v='3'/></baz>\n        ...     </row>\n        ...     <row>\n        ...         <foo>b</foo><baz><bar v='2'/></baz>\n        ...     </row>\n        ...     <row>\n        ...         <foo>c</foo><baz><bar v='2'/></baz>\n        ...     </row>\n        ... </table>'''\n        >>> with open('example3.xml', 'w') as f:\n        ...     f.write(d)\n        ...\n        223\n        >>> table3 = etl.fromxml('example3.xml', 'row',\n        ...                      {'foo': 'foo', 'bar': ('baz/bar', 'v')})\n        >>> table3\n        +------------+-----+\n        | bar        | foo |\n        +============+=====+\n        | ('1', '3') | 'a' |\n        +------------+-----+\n        | '2'        | 'b' |\n        +------------+-----+\n        | '2'        | 'c' |\n        +------------+-----+\n\n    If `lxml <http://lxml.de/>`_ is installed, full XPath expressions can be\n    used.\n\n    Note that the implementation is currently **not** streaming, i.e.,\n    the whole document is loaded into memory.\n\n    If multiple elements match a given field, all values are reported as a\n    tuple.\n\n    If there is more than one element name used for row values, a tuple\n    or list of paths can be provided, e.g.,\n    ``fromxml('example.html', './/tr', ('th', 'td'))``.\n\n    "
    source = read_source_from_arg(source)
    return XmlView(source, *args, **kwargs)

dataset/ETHPy150Open alimanfoo/petl/petl/io/xml.py fromxml/original