Skip to main content
edited for readability
Source Link
the Tin Man
  • 160.9k
  • 44
  • 222
  • 308

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation Installation:

pip install untangle

Usage Usage:

Your xmlXML file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessingAccessing the attributes with untangleuntangle:

import untangle

obj = untangle.parse('/path_to_xml_file/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

theThe output will be:

bar_name
1

More information about untangle can be found in "hereuntangle".
Also (if

Also, if you are curious), you can find a list of tools for working with XML and Python in "herePython and XML (you". You will also see that the most common ones were mentioned by previous answers).

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation

pip install untangle

Usage

Your xml file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessing the attributes with untangle:

import untangle

obj = untangle.parse('/path_to_xml_file/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

the output will be:

bar_name
1

More information about untangle can be found here.
Also (if you are curious), you can find a list of tools for working with XML and Python here (you will also see that the most common ones were mentioned by previous answers).

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation:

pip install untangle

Usage:

Your XML file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

Accessing the attributes with untangle:

import untangle

obj = untangle.parse('/path_to_xml_file/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

The output will be:

bar_name
1

More information about untangle can be found in "untangle".

Also, if you are curious, you can find a list of tools for working with XML and Python in "Python and XML". You will also see that the most common ones were mentioned by previous answers.

deleted 22 characters in body
Source Link
jchanger
  • 758
  • 10
  • 29

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation

pip install untangle

Usage

Your xml file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessing the attributes with untangle:

import untangle

obj = untangle.parse('/home/jesus/e_workspace/tests_again/srcpath_to_xml_file/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

the output will be:

bar_name
1

More information about untangle can be found here.
Also (if you are curious), you can find a list of tools for working with XML and Python here (you will also see that the most common ones were mentioned by previous answers).

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation

pip install untangle

Usage

Your xml file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessing the attributes with untangle:

import untangle

obj = untangle.parse('/home/jesus/e_workspace/tests_again/src/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

the output will be:

bar_name
1

More information about untangle can be found here.
Also (if you are curious), you can find a list of tools for working with XML and Python here (you will also see that the most common ones were mentioned by previous answers).

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation

pip install untangle

Usage

Your xml file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessing the attributes with untangle:

import untangle

obj = untangle.parse('/path_to_xml_file/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

the output will be:

bar_name
1

More information about untangle can be found here.
Also (if you are curious), you can find a list of tools for working with XML and Python here (you will also see that the most common ones were mentioned by previous answers).

Source Link
jchanger
  • 758
  • 10
  • 29

Just to add another possibility, you can use untangle, as it is a simple xml-to-python-object library. Here you have an example:

Installation

pip install untangle

Usage

Your xml file (a little bit changed):

<foo>
   <bar name="bar_name">
      <type foobar="1"/>
   </bar>
</foo>

accessing the attributes with untangle:

import untangle

obj = untangle.parse('/home/jesus/e_workspace/tests_again/src/file.xml')

print obj.foo.bar['name']
print obj.foo.bar.type['foobar']

the output will be:

bar_name
1

More information about untangle can be found here.
Also (if you are curious), you can find a list of tools for working with XML and Python here (you will also see that the most common ones were mentioned by previous answers).