Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python 2.6中的xml解析错误_Python_Xml_Python 3.x_Xml Parsing_Python 2.6 - Fatal编程技术网

python 2.6中的xml解析错误

python 2.6中的xml解析错误,python,xml,python-3.x,xml-parsing,python-2.6,Python,Xml,Python 3.x,Xml Parsing,Python 2.6,下面是解析下面发布的xml的脚本/函数。代码在python3上运行良好,当我移植到2.6TS时,给出以下错误 这里的isuue可能是什么 Traceback (most recent call last): File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__ return self.func(*args) File "D:\Squish\Run_Test2.6.py", line 214, in sel

下面是解析下面发布的xml的脚本/函数。代码在python3上运行良好,当我移植到2.6TS时,给出以下错误

这里的isuue可能是什么

Traceback (most recent call last):
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "D:\Squish\Run_Test2.6.py", line 214, in sel_submit
    xml_parser()
  File "D:\Squish\Run_Test2.6.py", line 59, in xml_parser
    for test in tree.findall('.//test[verification]'):
  File "C:\Python26\lib\xml\etree\ElementTree.py", line 647, in findall
    return self._root.findall(path)
  File "C:\Python26\lib\xml\etree\ElementTree.py", line 355, in findall
    return ElementPath.findall(self, path)
  File "C:\Python26\lib\xml\etree\ElementPath.py", line 198, in findall
    return _compile(path).findall(element)
  File "C:\Python26\lib\xml\etree\ElementPath.py", line 176, in _compile
    p = Path(path)
  File "C:\Python26\lib\xml\etree\ElementPath.py", line 93, in __init__
    "expected path separator (%s)" % (op or tag)
SyntaxError: expected path separator ([)
下面是代码

def xml_parser():
    # global variables
    global text_file
    global xml_list
    # File names
    xml_list = glob.glob("%s*.xml" % (os.path.join(SUITE_DIR +"/")))
    text_file = (os.path.join(SUITE_DIR)+"/Result_Summary-%s.txt"% (time.strftime("%Y-%m-%d")))
    with open("%s"%text_file,"w") as output:
            # Write Contents in the summary files
            output.write(' {} \n\n'.format('-' * 122))
            output.write('  Test Suite \t\t Test Name \t\t No Of PASS\t\t No Of FAIL\t\t Description\t\t \n')
            output.write(' {} \n\n'.format('-' * 122))
    for xml_name in xml_list:
        tree = ET.parse(xml_name)
        root = tree.getroot()
        with open("%s"%text_file,"a") as output:
            # Find all <test> elements with a <verification> child:
            for test in tree.findall('.//test[verification]'):
                # Collect passed and failed counts
                sut=tree.find('./test')
                passed = len(test.findall(".//result[@type='PASS']"))
                failed = len(test.findall(".//result[@type='FAIL']"))
                # Collect all the *last* <description> elements of type DETAILED
                descriptions = test.findall(".//result/description[@type='DETAILED'][last()]")
                # write a line of information to the file, including first desc
                output.write('{0}\t\t\t{1}\t\t\t{2}\t\t\t{3}\t\t{4}\n\n'.format(
                    sut.attrib['name'],test.attrib['name'], passed, failed, descriptions[0].text))
                # write remaining descriptions
                for desc in descriptions[1:]:
                    output.write('\t\t\t\t\t\t\t\t\t\t\t{0}\n'.format(desc.text))

Python2.6不支持XPath(它是在随附的中引入的)


因此,您应该将Python2升级到2.7,或者修改代码以避免XPath。

下面的行passed=len(test.findall(“.//result[@type='PASS'])failed=len(test.findall(.//result[@type='FAIL'])有什么好替换的
   <SquishReport version="2.0">
    <test name="HMI_testing_debug">
        <prolog time="2013-01-25T16:51:58+05:30"/>
        <test name="tst_Setup_me">
            <prolog time="2013-01-25T16:51:58+05:30"/>
            <verification line="7" file="D:/Squish/HMI_testing_debug/tst_Setup_me/test.py" name="Is TEMP is disabled">
                <result type="PASS" time="2013-01-25T16:52:00+05:30">
                    <description>Comparison</description>
                    <description type="DETAILED">'0' and 'False' are equal</description>
                    <description type="DETAILED">Is TEMP is disabled</description>
                </result>
            </verification>
            <message line="9" type="ERROR" file="D:/Squish/HMI_testing_debug/tst_Setup_me/test.py" time="2013-01-25T16:52:21+05:30"><![CDATA[LookupError: Object ':_QMenu' not found. Could not match properties:
    type for object name: ':_QMenu']]></message>
            <epilog time="2013-01-25T16:52:21+05:30"/>
        </test>
        <epilog time="2013-01-25T16:52:21+05:30"/>
    </test>
</SquishReport>
def xml_parser():
    # global variables
    global text_file
    global xml_list
    # File names
    xml_list = glob.glob("%s*.xml" % (os.path.join(SUITE_DIR +"/")))
    text_file = (os.path.join(SUITE_DIR)+"/Result_Summary-%s.txt"% (time.strftime("%Y-%m-%d")))
    with open("%s"%text_file,"w") as output:
            # Write Contents in the summary files
            output.write(format('-' * 122))
            output.write('  \nTest Suite \t\t Test Name \t\t No Of PASS\t\t No Of FAIL\t\t Description\t\t \n')
            output.write(format('-' * 122))
    for xml_name in xml_list:
        print(xml_name)
        tree = ET.parse(xml_name)
        root = tree.getroot()
        with open("%s"%text_file,"a") as output:
            for suite_x in tree.findall('./test'):
                output.write('\n')
                print(suite_x.attrib['name'])
                output.write(suite_x.attrib['name'])
                output.write('\t\t')
                for test_x in suite_x.findall('.//test'):
                    nextline = 0
                    output.write(test_x.attrib['name'])
                    output.write('\t\t')
                    print(test_x.attrib['name'])                
                    for veri_x in test_x.findall('./verification'):
                        passed = 0
                        failed = 0
                        for count in veri_x:
                            if(nextline):
                                output.write('\n')
                                output.write('\t\t\t\t\t\t')
                            if( count.attrib['type']=='PASS'):
                                passed=passed+1
                            elif( count.attrib['type']=='FAIL'):
                                failed=failed+1
                            output.write(str(passed))
                            output.write('\t\t')
                            output.write(str(failed))
                            output.write('\t\t')
                            print("passed: %s" %passed,"failed: %s" %failed)
                            print(veri_x.attrib['name'])
                            output.write(veri_x.attrib['name'])
                            nextline = 1