idZddlmZddlZddlmZddlmZmZddl m Z ddl m Z ddl mZmZdd lmZdd lmZdd lmZdd lmZmZmZmZmZdd lmZer0ddlmZm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0GddZ1Gdde1Z2Gdde1Z3dLd!Z4dMd&Z5dNd)Z6e j7fdOdBZ8edCdDddEdEdddddFdGdddHde j7dIdPdKZ9dS)Qz5 :mod:``pandas.io.xml`` is a module for reading XML. ) annotationsN)PathLike) TYPE_CHECKINGAny)lib)import_optional_dependency)AbstractMethodError ParserError) set_module)check_dtype_backend) is_list_like) get_handleinfer_compression is_fsspec_urlis_urlstringify_path) TextParser)CallableSequence)Element)etree) CompressionOptions ConvertersArgDtypeArg DtypeBackendFilePath ParseDatesArg ReadBufferStorageOptions XMLParsers) DataFramecJeZdZdZd-dZd.d!Zd/d$Zd0d&Zd1d'Zd2d(Z d3d+Z d,S)4_XMLFrameParsera: Internal subclass to parse XML into DataFrames. Parameters ---------- path_or_buffer : a valid JSON ``str``, path object or file-like object Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. xpath : str or regex The ``XPath`` expression to parse required set of nodes for migration to :class:`~pandas.DataFrame`. ``etree`` supports limited ``XPath``. namespaces : dict The namespaces defined in XML document (``xmlns:namespace='URI'``) as dicts with key being namespace and value the URI. elems_only : bool Parse only the child elements at the specified ``xpath``. attrs_only : bool Parse only the attributes at the specified ``xpath``. names : list Column names for :class:`~pandas.DataFrame` of parsed XML data. dtype : dict Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32, 'c': 'Int64'} converters : dict, optional Dict of functions for converting values in certain columns. Keys can either be integers or column labels. parse_dates : bool or list of int or names or list of lists or dict Converts either index or select columns to datetimes encoding : str Encoding of xml object or document. stylesheet : str or file-like URL, file, file-like object, or a raw string containing XSLT, ``etree`` does not support XSLT but retained for consistency. iterparse : dict, optional Dict with row element as key and list of descendant elements and/or attributes as value to be retrieved in iterparsing of XML document. compression : str or dict, default 'infer' For on-the-fly decompression of on-disk data. If 'infer' and 'path_or_buffer' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). If using 'zip' or 'tar', the ZIP file must contain only one data file to be read in. Set to ``None`` for no decompression. Can also be a dict with key ``'method'`` set to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdDecompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. As an example, the following could be passed for Zstandard decompression using a custom compression dictionary: ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``. storage_options : dict, optional Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to ``urllib.request.Request`` as header options. For other URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more details, and for more examples on storage options refer `here `_. See also -------- pandas.io.xml._EtreeFrameParser pandas.io.xml._LxmlFrameParser Notes ----- To subclass this class effectively you must override the following methods:` * :func:`parse_data` * :func:`_parse_nodes` * :func:`_iterparse_nodes` * :func:`_parse_doc` * :func:`_validate_names` * :func:`_validate_path` See each method's respective documentation for details on their functionality. path_or_buffer.FilePath | ReadBuffer[bytes] | ReadBuffer[str]xpathstr namespacesdict[str, str] | None elems_onlybool attrs_onlynamesSequence[str] | NonedtypeDtypeArg | None convertersConvertersArg | None parse_datesParseDatesArg | Noneencoding str | None stylesheet5FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None iterparsedict[str, list[str]] | None compressionrstorage_optionsrreturnNonec||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ dSN)r$r&r(r*r,r-r/r1r3r5r7r9r;r<)selfr$r&r(r*r,r-r/r1r3r5r7r9r;r<s ?C:\PYTHON\GemmaReport\python\Lib\site-packages\pandas/io/xml.py__init__z_XMLFrameParser.__init__sp"- $$$  $&  $"/:.list[dict[str, str | None]]c t|)z Parse xml data. This method will call the other internal methods to validate ``xpath``, names, parse and return specific nodes. r rAs rB parse_dataz_XMLFrameParser.parse_datas"$'''rDelems list[Any]cjrjrtdjr#jrfd|D}nCd|D}n6jr d|D}n"jrfd|D}n d|D}d|D}t t d|Dfd |D}jrfd |D}|S) aA Parse xml nodes. This method will parse the children and attributes of elements in ``xpath``, conditionally for only elements, only attributes or both while optionally renaming node names. Raises ------ ValueError * If only elements and only attributes are specified. Notes ----- Namespace URIs will be removed from return node values. Also, elements with missing children or attributes compared to siblings will have optional keys filled with None values. z4Either element or attributes can be parsed not both.c g|]h}i|jr'|js|j|jinidtj|ddDiS)c6i|]\}}||jr|jndSr@text.0nmchs rB z;_XMLFrameParser._parse_nodes...s; &B27 <rD*Tstrict)rPisspacetagzipr-findallrRelrAs rB z0_XMLFrameParser._parse_nodes..s     "w$/1w/@/@$RVRW--!#  *-dj"**S//RV*W*W*W    rDcLg|]!}d|dD"S)c:i|]}|j|jr|jndSr@rZrPrRrTs rBrUz;_XMLFrameParser._parse_nodes...s)TTTbRV9RWWTTTTrDrVr\rRr^s rBr_z0_XMLFrameParser._parse_nodes..sAUTBJJsOOTTTrDcTg|]%}d|jD&S)c"i|] \}}||r|nd Sr@rRkvs rBrUz;_XMLFrameParser._parse_nodes...s'CCCA$AACCCrDattribitemsres rBr_z0_XMLFrameParser._parse_nodes..s@HJCC1B1BCCCrDc g|]o}i|j|jr'|js|j|jinidt j|ddDpS)c6i|]\}}||jr|jndSr@rOrQs rBrUz;_XMLFrameParser._parse_nodes...s;"Brw8BGGDrDrVFrW)rmrPrYrZr[r-r\r]s rBr_z0_XMLFrameParser._parse_nodes..s   i,.GUBGOO.. s)VVVrv"';rwwtVVVrDrV)rmrPrYrZr\res rBr_z0_XMLFrameParser._parse_nodes..s  i,.GUBGOO..s8 I I Itq!qQWWS\\!__a I I IrD)rnrRds rBr_z0_XMLFrameParser._parse_nodes..s<   NO I Iqwwyy I I I   rDc@g|]}|D]}|SrhkeysrRryrjs rBr_z0_XMLFrameParser._parse_nodes..-"F"F"FQVVXX"F"F1"F"F"F"FrDc.g|]fdDS)cRi|]#}||vr|nd$Sr@r{rRrjrys rBrUz;_XMLFrameParser._parse_nodes...3CCC!Q!&&((]]QqTTCCCrDrhrRryr|s @rBr_z0_XMLFrameParser._parse_nodes../SSSCCCCdCCCSSSrDc |g|]8}ttj|d9STrWdictr[r-valuesrRryrAs rBr_z0_XMLFrameParser._parse_nodes..:SSST#dj!((**TBBBCCSSSrD)r*r, ValueErrorr-listrfromkeys)rArJdictsr|s` @rB _parse_nodesz_XMLFrameParser._parse_nodess, ? Ut USTT T ?0 z     $   # _ NSEEZ         EE  E  SX   DMM"F"Fe"F"F"FGGHHSSSSUSSS : TSSSSUSSSE rDrc: g}d}tjts)tt jjdjr3t tjnd}tj|s*tt j|dtj dstj ttfrqtj s]tj sItj trj dst#j dt%dt'j|t't)j|k}|j d D]\}}d |jvr |jd d n|j}|d kr||kri}|jr|rt1j|jdD]x\} } || kr/|jr|jnd} | |vr | |vr| || <| |jvr5|j| |vr| |vr|j| || <ynBj|D]4} || kr|jr|jnd|| <| |jvr|j| || <5|dkr||kr|||d}|t|dre|Q|=|d=||=|gkrt%dtAt!d|D fd|D}jrfd|D}|S)a# Iterparse xml nodes. This method will read in local disk, decompressed XML files for elements and underlying descendants using iterparse, a method to iterate through an XML tree without holding entire XML tree in memory. Raises ------ TypeError * If ``iterparse`` is not a dict or its dict value is not list-like. ParserError * If ``path_or_buffer`` is not a physical file on disk or file-like object. * If no data is returned from selected items in ``iterparse``. Notes ----- Namespace URIs will be removed from return node values. Also, elements with missing children or attributes in submitted list will have optional keys filled with None values. Nz" is not a valid type for iterparsez+ is not a valid type for value in iterparseread)z.~r~rDc.g|]fdDS)cRi|]#}||vr|nd$Sr@r{rs rBrUz?_XMLFrameParser._iterparse_nodes...rrDrhrs @rBr_z4_XMLFrameParser._iterparse_nodes..rrDc |g|]8}ttj|d9Srrrs rBr_z4_XMLFrameParser._iterparse_nodes..rrD)" isinstancer9r TypeErrortype__name__nextiterr|r hasattrr$r'rrr startswithrr lensetrZrwr-r[rPrrmappendclearr getparentrr) rAr9rrowrow_nodeiterparse_repeatseventelem curr_elemcolrSelem_valr|s ` @rB_iterparse_nodesz _XMLFrameParser._iterparse_nodessy..0,0$.$// ''0TTT 9=N4T^002233444BDN8455 x011)))  +V44 4.h@@ d)** T011  4.44  '22>BB !!4g>>JL   x 899S x( ) )> >  %9T%8AQRRR% 0% 0KE425//s++A..txI((C:8"38#&x0$*T$$$ ; ;R%++48I'Gtyy4H'szz||;;# *2B$+--#{3/szz||CCRU *.+c*:B ; $~h788$++48I'Gtyy4CH$+--'+{3'7CH~~((S_LL%%%C 4//0((**64>>;K;K;W NN,,Q/((**64>>;K;K;W B;;KLL LDMM"F"Fe"F"F"FGGHHSSSSUSSS : TSSSSUSSSE rDc t|)a* Validate ``xpath``. This method checks for syntax, evaluation, or empty nodes return. Raises ------ SyntaxError * If xpah is not supported or issues with namespaces. ValueError * If xpah does not return any nodes. rGrHs rB_validate_pathz_XMLFrameParser._validate_paths"$'''rDc t|)z Validate names. This method will check if names is a list-like and aligns with length of parse nodes. Raises ------ ValueError * If value is not a list and less then length of nodes. rGrHs rB_validate_namesz_XMLFrameParser._validate_namess"$'''rDraw_docElement | etree._Elementc t|)z Build tree from path_or_buffer. This method will parse XML object into tree either from string/bytes or file location. rG)rArs rB _parse_docz_XMLFrameParser._parse_docs"$'''rDN)r$r%r&r'r(r)r*r+r,r+r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;rr<rr=r>r=rE)rJrKr=rE)r9rr=rEr=rKr=r>)rr%r=r) r __module__ __qualname____doc__rCrIrrrrrrhrDrBr#r#:s^^@////@((((TTTTliiiiV((((" ( ( ( ( ( ( ( ( ( (rDr#c2eZdZdZddZddZddZdd Zd S)_EtreeFrameParserz Internal class to parse XML into DataFrames with the Python standard library XML module: `xml.etree.ElementTree`. r=rEc<ddlm}|jtd|j3||j|_|}||j| |n| |}|S)Nrr9zBTo use stylesheet, you need lxml installed and selected as parser.) xml.etree.ElementTreer9r7rrr$xml_docrrrrrAr9rJ xml_dictss rBrIz_EtreeFrameParser.parse_datas333333 ? &T  > !??4+>??DL''))E ~%   e $ $ $&&y11  rDrKcd} |j|j|j}d|D}d|D}|t ||S|jr|gkrt ||jr|ikrt ||gkr|ikrt |n)#ttf$r}td|d}~wwxYw|S)z Notes ----- ``etree`` supports limited ``XPath``. If user attempts a more complex expression syntax error will raise. xpath does not return any nodes or attributes. Be sure to specify in `xpath` the parent nodes of children and attributes to parse. If document uses namespaces denoted with xmlns, be sure to define namespaces and use them in xpath.r(cBg|]}|dD]}|SrVrdrRr^rTs rBr_z4_EtreeFrameParser._validate_path..s/EEErRZZ__EErEEEErDcRi|]$}|jD]\}}|| %SrhrlrRr^rjrks rBrUz4_EtreeFrameParser._validate_path..s7HHHbbioo6G6GHHdaQHHHHrDNzxYou have used an incorrect or unsupported XPath expression for etree library or you used an undeclared namespace prefix.) rr\r&r(rr*r,KeyError SyntaxError)rAmsgrJchildrenattrserrs rBrz _EtreeFrameParser._validate_paths  !  L(((PPEEEUEEEHHHEHHHE} oo% ?*x2~~$S//)?*u{{$S//)r>>erkk$S//)+&   /    sB$B))C:C  Cr>c|jr|jr-|jtt|j}n?|j|j|j}||dng}t|jr6t|jt|krtddStt|jjddS)NrrV7names does not match length of child elements in xpath. is not a valid type for names)r-r9rrrfindr&r(r\r rrrrr)rArparents rBrz!_EtreeFrameParser._validate_namess : ~ M>$tDN/C/C*D*DE**4:$/*RR282D6>>#..."DJ'' tz??S]]22$Q32  DJ''0PPP  rDrr%rcddlm}m}t||j|j|j}|5}||j}|||}dddn #1swxYwY|S)Nr) XMLParserparsefilepath_or_bufferr5r;r<r5parser)rrrget_data_from_filepathr5r;r<getroot)rArrr handle_dataxml_data curr_parserdocuments rBrz_EtreeFrameParser._parse_doc s        -&]( 0     ;H#)T];;;KuXk:::H ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;!!!sAAANrrr)rr%r=r)rrrrrIrrrrhrDrBrrso ,''''R(""""""rDrc:eZdZdZddZddZddZdd ZddZdS)_LxmlFrameParserz Internal class to parse XML into :class:`~pandas.DataFrame` with third-party full-featured XML library, ``lxml``, that supports ``XPath`` 1.0 and XSLT 1.0. r=rEcddlm}|jr||j|_|jr8||j|_||_|}| |j| |n| |}|S)z Parse xml data. This method will call the other internal methods to validate ``xpath``, names, optionally parse and run XSLT, and parse original or transformed XML and return specific nodes. rr) lxml.etreer9rr$rr7xsl_doc_transform_docrrrrrs rBrIz_LxmlFrameParser.parse_data's )((((( > !??4+>??DL 5#t?? #2244 ''))E ~%   e $ $ $&&y11  rDrKcbd}|j|j|j}d|D}d|D}|gkrt||gkrS|jr|gkrt||jr|ikrt||gkr|ikrt||S)NrrcBg|]}|dD]}|Sr)r&rs rBr_z3_LxmlFrameParser._validate_path..Os/???2#??2B????rDcRi|]$}|jD]\}}|| %Srhrlrs rBrUz3_LxmlFrameParser._validate_path..Ps7DDD"")//2C2CDD$!QADDDDrD)rr&r(rr*r,)rArrJrrs rBrz_LxmlFrameParser._validate_pathDs !  ""4:$/"JJ?????DDDDD B;;S// ! B;; &8r>> oo% &5B;; oo%2~~%2++ oo% rDr>c|jr|jr-|jtt|j}n)|j|jdz|j}t|jr6t|jt|krtddStt|jj ddS)Nz[1]/*rrr) r-r9rrrr&r(r rrrrr)rArs rBrz _LxmlFrameParser._validate_names_s : ~ >$tDN/C/C*D*DE<--J(T_.DJ'' tz??S]]22$Q32  DJ''0PPP  rDrr%etree._Elementcddlm}m}m}t ||j|j|j}|5}||j}t|tj rN|jtd|| |j|}n |||}dddn #1swxYwY|S)Nr)r fromstringrrrz2Can not pass encoding None when input is StringIO.r)rrrrrr5r;r<rioStringIOrgetvalueencode) rArrrrrrrrs rBrz_LxmlFrameParser._parse_doctsU          -&]( 0     ?H#)T];;;K(BK00 ?=(#L&:%%''..t}==k!5+>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sBCC Cetree._XSLTResultTreecRddlm}||j}||j}|S)z Transform original tree using stylesheet. This method will transform original xml using XSLT script into am ideally flatter xml document for easier parsing and migration to Data Frame. r)XSLT)rrrr)rAr transformernew_docs rBrz_LxmlFrameParser._transform_docs= $#####d4<(( +dl++rDNrrr)rr%r=r)r=r) rrrrrIrrrrrhrDrBrr s :6*B      rDrrr%r5r6r;rr<rct|}t|d|||5}t|jdr&t |jn|j cdddS#1swxYwYdS)z Extract raw XML data. The method accepts two input types: 1. filepath (string-like) 2. file-like object (e.g. open file object, StringIO) r)r5r;r<rN)rrrhandlepreprocess_datar)rr5r;r< handle_objs rBrrs((:;;  '      z(&11 #OJ-2244 5 5 5"                    sAA44A8;A8data&str | bytes | io.StringIO | io.BytesIOr=io.StringIO | io.BytesIOct|trtj|}n)t|trtj|}|S)z Convert extracted raw data. This method will return underlying data of extracted XML content. The data either has a `read` attribute (e.g. a file object or a StringIO/BytesIO) or is a string or bytes that is an XML document. )rr'rrbytesBytesIO)rs rBrrsM$ {4   D%  z$ KrDrEr!c tt|}d|D} t|fd|i|5}|cdddS#1swxYwYdS#t$r}t d|d}~wwxYw)z Convert parsed data to Data Frame. This method will bind xml dictionary data of keys and values into named columns of Data Frame using the built-in TextParser class that build Data Frame and infers specific dtypes. cPg|]#}t|$Srh)rrrxs rBr_z"_data_to_frame..s( , , ,!T!((**   , , ,rDr-NzqXML document may be too complex for import. Try to flatten document and use distinct element and attribute names.)rrrrr )rkwargstagsnodestprs rB_data_to_framers T  D , ,t , , ,E  4 4T 4V 4 4 7799                    +    s:A'A A'AA'!A"A'' B1BBr$r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4rr r7r8r9r: dtype_backendDtypeBackend | lib.NoDefaultc <| dkr?tdd}|t|||||||||| | | | |}nAtd| dkrt|||||||||| | | | |}nt d|}t d |||||d |S) a Call internal parsers. This method will conditionally call internal parsers: LxmlFrameParser and/or EtreeParser. Raises ------ ImportError * If lxml is not installed if selected as parser. ValueError * If parser is not lxml or etree. lxmlz lxml.etreeignore)errorsNz7lxml not found, please install or use the etree parser.rz,Values for parser can only be lxml or etree.)rr/r1r3rrh)rr ImportErrorrrrIr)r$r&r(r*r,r-r/r1r3r5rr7r9r;r<rrrp data_dictss rB_parsers H),xHHH   AA"WXX X 7                   "GHHHJ   #       rDpandasz./*Fzutf-8rr)r&r(r*r,r-r/r1r3r5rr7r9r;r<rStorageOptions | Nonect|tdid|d|d|d|d|d|d|d|d |d | d | d | d | d| d|d|S)a+ Read XML document into a :class:`~pandas.DataFrame` object. Parameters ---------- path_or_buffer : str, path object, or file-like object String path, path object (implementing ``os.PathLike[str]``), or file-like object implementing a ``read()`` function. The string can be a path. The string can further be a URL. Valid URL schemes include http, ftp, s3, and file. xpath : str, optional, default './\*' The ``XPath`` to parse required set of nodes for migration to :class:`~pandas.DataFrame`.``XPath`` should return a collection of elements and not a single element. Note: The ``etree`` parser supports limited ``XPath`` expressions. For more complex ``XPath``, use ``lxml`` which requires installation. namespaces : dict, optional The namespaces defined in XML document as dicts with key being namespace prefix and value the URI. There is no need to include all namespaces in XML, only the ones used in ``xpath`` expression. Note: if XML document uses default namespace denoted as `xmlns=''` without a prefix, you must assign any temporary namespace prefix such as 'doc' to the URI in order to parse underlying nodes and/or attributes. elems_only : bool, optional, default False Parse only the child elements at the specified ``xpath``. By default, all child elements and non-empty text nodes are returned. attrs_only : bool, optional, default False Parse only the attributes at the specified ``xpath``. By default, all attributes are returned. names : list-like, optional Column names for DataFrame of parsed XML data. Use this parameter to rename original element names and distinguish same named elements and attributes. dtype : Type name or dict of column -> type, optional Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32, 'c': 'Int64'} Use `str` or `object` together with suitable `na_values` settings to preserve and not interpret dtype. If converters are specified, they will be applied INSTEAD of dtype conversion. converters : dict, optional Dict of functions for converting values in certain columns. Keys can either be integers or column labels. parse_dates : bool or list of int or names or list of lists or dict, default False Identifiers to parse index or columns to datetime. The behavior is as follows: * boolean. If True -> try parsing the index. * list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column. * list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column. * dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call result 'foo' encoding : str, optional, default 'utf-8' Encoding of XML document. parser : {'lxml','etree'}, default 'lxml' Parser module to use for retrieval of data. Only 'lxml' and 'etree' are supported. With 'lxml' more complex ``XPath`` searches and ability to use XSLT stylesheet are supported. stylesheet : str, path object or file-like object A URL, file-like object, or a string path containing an XSLT script. This stylesheet should flatten complex, deeply nested XML documents for easier parsing. To use this feature you must have ``lxml`` module installed and specify 'lxml' as ``parser``. The ``xpath`` must reference nodes of transformed XML document generated after XSLT transformation and not the original XML document. Only XSLT 1.0 scripts and not later versions is currently supported. iterparse : dict, optional The nodes or attributes to retrieve in iterparsing of XML document as a dict with key being the name of repeating element and value being list of elements or attribute names that are descendants of the repeated element. Note: If this option is used, it will replace ``xpath`` parsing and unlike ``xpath``, descendants do not need to relate to each other but can exist any where in document under the repeating element. This memory- efficient method should be used for very large XML files (500MB, 1GB, or 5GB+). For example, ``{"row_element": ["child_elem", "attr", "grandchild_elem"]}``. compression : str or dict, default 'infer' For on-the-fly decompression of on-disk data. If 'infer' and 'path_or_buffer' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). If using 'zip' or 'tar', the ZIP file must contain only one data file to be read in. Set to ``None`` for no decompression. Can also be a dict with key ``'method'`` set to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdDecompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. As an example, the following could be passed for Zstandard decompression using a custom compression dictionary: ``compression={'method': 'zstd', 'dict_data': my_compression_dict}``. storage_options : dict, optional Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to ``urllib.request.Request`` as header options. For other URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more details, and for more examples on storage options refer `here `_. dtype_backend : {'numpy_nullable', 'pyarrow'} Back-end data type applied to the resultant :class:`DataFrame` (still experimental). If not specified, the default behavior is to not use nullable data types. If specified, the behavior is as follows: * ``"numpy_nullable"``: returns nullable-dtype-backed :class:`DataFrame` * ``"pyarrow"``: returns pyarrow-backed nullable :class:`ArrowDtype` :class:`DataFrame` .. versionadded:: 2.0 Returns ------- df A DataFrame. See Also -------- read_json : Convert a JSON string to pandas object. read_html : Read HTML tables into a list of DataFrame objects. Notes ----- This method is best designed to import shallow XML documents in following format which is the ideal fit for the two-dimensions of a ``DataFrame`` (row by column). :: data data data ... ... ... As a file format, XML documents can be designed any way including layout of elements and attributes as long as it conforms to W3C specifications. Therefore, this method is a convenience handler for a specific flatter design and not all possible XML structures. However, for more complex XML documents, ``stylesheet`` allows you to temporarily redesign original document with XSLT (a special purpose language) for a flatter version for migration to a DataFrame. This function will *always* return a single :class:`DataFrame` or raise exceptions due to issues with XML document, ``xpath``, or other parameters. See the :ref:`read_xml documentation in the IO section of the docs ` for more information in using this method to parse XML files to DataFrames. Examples -------- >>> from io import StringIO >>> xml = ''' ... ... ... square ... 360 ... 4.0 ... ... ... circle ... 360 ... ... ... ... triangle ... 180 ... 3.0 ... ... ''' >>> df = pd.read_xml(StringIO(xml)) >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml = ''' ... ... ... ... ... ''' >>> df = pd.read_xml(StringIO(xml), xpath=".//row") >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml = ''' ... ... ... square ... 360 ... 4.0 ... ... ... circle ... 360 ... ... ... ... triangle ... 180 ... 3.0 ... ... ''' >>> df = pd.read_xml( ... StringIO(xml), ... xpath="//doc:row", ... namespaces={"doc": "https://example.com"}, ... ) >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml_data = ''' ... ... ... 0 ... 1 ... 2.5 ... True ... a ... 2019-12-31 00:00:00 ... ... ... 1 ... 4.5 ... False ... b ... 2019-12-31 00:00:00 ... ... ... ''' >>> df = pd.read_xml( ... StringIO(xml_data), dtype_backend="numpy_nullable", parse_dates=["e"] ... ) >>> df index a b c d e 0 0 1 2.5 True a 2019-12-31 1 1 4.5 False b 2019-12-31 r$r&r(r*r,r-r/r1r3r5rr7r9r;r<rrh)r r)r$r&r(r*r,r-r/r1r3r5rr7r9r;r<rs rBread_xmlr GsR  &&&    %~ e : :   :   e  e :  K  v : )  K (  $m! rD)rr%r5r6r;rr<r)rrr=r)rrEr=r!)"r$r%r&r'r(r)r*r+r,r+r-r.r/r0r1r2r3r4r5r6rr r7r8r9r:r;rr<rrrr=r!)"r$r%r&r'r(r)r*r+r,r+r-r.r/r0r1r2r3r4r5r6rr r7r8r9r:r;rr<rrrr=r!):r __future__rrosrtypingrr pandas._libsrpandas.compat._optionalr pandas.errorsr r pandas.util._decoratorsr pandas.util._validatorsr pandas.core.dtypes.commonr pandas.io.commonrrrrrpandas.io.parsersrcollections.abcrrrrrrpandas._typingrrrrrrrrr rr!r#rrrrr no_defaultrr rhrDrBr/s#"""""  >>>>>>/.....777777222222)(((((!.-----                      !     t(t(t(t(t(t(t(t(n l"l"l"l"l"l"l"l"^BBBBBBBBJ    8(N36.!XXXXXv H(,"&!'+(,"HL-1&--125.%{{{{{{{{rD