我正在使用这个库来解析我的xml:
import xml.etree.cElementTree as xml
解析器的xml输入是subprocess.Popen
的输出:
XMLFile = subprocess.Popen(xml_command,shell=True,stdout=subprocess.PIPE, executable="/bin/ksh").communicate()[0]
root = xml.XML(XMLFile)
我收到此错误:
IOError: [Errno 36] File name too long: ' <?xml version=\...'
但是,当我传递与文件相同的命令xml_command
生成的xml时,它完全正常:
root = xml.parse("/home/test.xml")
答案 0 :(得分:0)
试试这个:
import xml.etree.cElementTree as xml
p = subprocess.Popen(xml_command, shell=True, stdout=subprocess.PIPE, executable="/bin/ksh")
text, err = p.communicate()
root = xml.fromstring(text)
使用python 2.6.6
答案 1 :(得分:-1)
试试这个
from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))