-1

The value which is coming to my variable is:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">411,00</string>

I want to take 411 from there. How can I do this?

Enis D.
  • 121
  • 11

1 Answers1

1

Use lxml like this:

from lxml import etree

tree = etree.parse("filename.xml")
print tree.xpath('//text()')[0]

You can use StringIO to pass an xml code:

from lxml import etree
from StringIO import StringIO

tree = etree.parse(StringIO('<?xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/">411,00</string>'))
print tree.xpath('//text()')[0]

parse methode expects source to be one of the following:

filename
file object or file-like object
URL using HTTP or FTP protocol

Kenly
  • 24,317
  • 7
  • 44
  • 60