Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse XML using python
    primarykey
    data
    text
    <p>I am trying to parse an xml using python for create a result summary file. Below is my code and a snippet of xml, Like the below i have couple of sections with <code>&lt;test&gt;</code> and <code>&lt;/test&gt;</code></p> <pre class="lang-xml prettyprint-override"><code>&lt;test name="tst_case1"&gt; &lt;prolog time="2013-01-18T14:41:09+05:30"/&gt; &lt;verification name="VP5" file="D:/Squish/HMI_testing/tst_case1/test.py" type="properties" line="6"&gt; &lt;result time="2013-01-18T14:41:10+05:30" type="PASS"&gt; &lt;description&gt;VP5: Object propertycomparisonof ':_QMenu_3.enabled'passed&lt;/description&gt; &lt;description type="DETAILED"&gt;'false' and 'false' are equal&lt;/description&gt; &lt;description type="object"&gt;:_QMenu_3&lt;/description&gt; &lt;description type="property"&gt;enabled&lt;/description&gt; &lt;description type="failedValue"&gt;false&lt;/description&gt; &lt;/result&gt; &lt;/verification&gt; &lt;epilog time="2013-01-18T14:41:11+05:30"/&gt; &lt;/test&gt; </code></pre> <p>What I want to get is, in one <code>&lt;test&gt;</code> section how many PASS / FAIL is there.</p> <p>With the below code its printing the total pass/Fail in the xml file.But i am interested in each section how many PASS/FAIL. can any boy tell me the procedure to fetchout this ?</p> <pre class="lang-py prettyprint-override"><code>import sys import xml.dom.minidom as XY file = open("result.txt", "w") tree = XY.parse('D:\\Squish\\squish results\\Results-On-2013-01-18_0241 PM.xml') Test_name = tree.getElementsByTagName('test') Test_status = tree.getElementsByTagName('result') count_testname =0 passcount = 0 failcount = 0 Test_name_array = [] for my_Test_name in Test_name: count_testname = count_testname+1 passcount = 0 failcount = 0 my_Test_name_final = my_Test_name.getAttribute('name') Test_name_array = my_Test_name_final if(count_testname &gt; 1): print(my_Test_name_final) for my_Test_status in Test_status: my_Test_status_final = my_Test_status.getAttribute('type') if(my_Test_status_final == 'PASS'): passcount = passcount+1 if(my_Test_status_final == 'FAIL'): failcount = failcount+1 print(str(my_Test_status_final)) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload