Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I (also) wouldn't use BeautifulSoup for this, and though I like lxml, that's an extra install, and if you don't want to bother, this is simple enough to do with the standard lib ElementTree module.</p> <p>Something like:</p> <pre><code>import xml.etree.ElementTree as ET import sys tree=ET.parse( 'test.xml' ) root=tree.getroot() rs=root.getchildren() keys = rs[0].attrib.keys() for a in keys: sys.stdout.write(a); sys.stdout.write('\t') sys.stdout.write('\n') for r in rs: assert keys == r.attrib.keys() for k in keys: sys.stdout.write( r.attrib[k]); sys.stdout.write('\t') sys.stdout.write('\n') </code></pre> <p>will, from python-3, produce :</p> <pre><code>zip m_name current city cust_ID l_name f_name 00010 OfThe 1 Fairbanks B123456@Y1996 Jungle George 03010 P 1 Yellow River Q975697@Z2000 Freely I 07008 0 Fallen Arches M7803@J2323 Jungle Jim </code></pre> <p>Note that with Python-2.7, the order of the attributes will be different. If you want them to output in a different specific order, you should sort or order the list "keys" . </p> <p>The assert is checking that all rows have the same attributes. If you actually have missing or different attributes in the elements, then you'll have to remove that and add some code to deal with the differences and supply defaults for missing values. ( In your sample data, you have a null value ( m_name="" ), rather than a missing value. You might want to check that this case is handled OK by the consumer of this output, or else add some more special handling for this case. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload