Jun-25-2020, 01:59 AM
Thanks for weighing in.
Here is the code
INPUT Data
==============
<?xml version="1.0" encoding="UTF-8"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2012</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
The python code ==> xmltest.py
It is sitting in the home directory with u+x permission
If I use ./xmltest.py throw file not found
Running this in window make output, but Linux is not making output.
I ran with python -v xmltest.py.
I did not see any errors there as well.
Thanks for your guidance.
Here is the code
#!/usr/bin/python def Process_XML(infile, inxpath, xpathdln): """ Process XML Xpath """ import xml.etree.ElementTree as ET from lxml import etree tree = etree.parse(infile) root = tree.getroot() print(root) for dln in tree.xpath(xpathdln): # Iterate over attributes of datafield print(dln.tag + ' = ' + dln.text) for df in tree.xpath(inxpath): # Iterate over attributes of datafield print(df.tag + ' = ' + df.text) for attrib_name in df.attrib: print( '@' + attrib_name + '=' + df.attrib[attrib_name]) # subfield is a child of datafield, and iterate subfields = df.getchildren() for subfield in subfields: print (subfield.tag + ' = ' + subfield.text) return; infile1 = '<CountryData.xml> # Given below inxpath1 = '//Country' xpathdln = '/data' Process_XML(infile1, inxpath1, xpathdln)The above code is tested in windows Python 3.8.1, but Linux has Python 2
INPUT Data
==============
<?xml version="1.0" encoding="UTF-8"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2012</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
The python code ==> xmltest.py
It is sitting in the home directory with u+x permission
If I use ./xmltest.py throw file not found
Running this in window make output, but Linux is not making output.
I ran with python -v xmltest.py.
I did not see any errors there as well.
Thanks for your guidance.