I need to cut strings from a line(xml file) and save them in an array
<p>i have another question regarding python. I need to save a specific string of a xml file(the string appears several times in the file) in a list.</p>

<pre><code>def parse_xml(self):
    file_ = open("ErrorReactions_TestReport_20160831_165153.xml", "r")
    for line in file_:
        line.rstrip()
        if "result_str" in line:
            if line == "Skipped":
                "count how much test cases are skipped"
            elif  line == "Failed"
                "count how much test cases failed
            else:
                "count how much test cases passed"
</code></pre>

<p>This is my code, my problem is that i need to save the string behind the parameter result_str and check if they match with "Skipped" or "Failed". How do i get that string saved in a variable?
The lines look like this:</p>

<p>&lt; verdict time="1472654306.7" result_str="Passed" result="2">Generator run successfully&lt; /verdict>
&lt; verdict time="1472654306.7" result_str="Skipped" result="0" final="True">Testgenerator not active&lt; /verdict></p>

<p>Regex is one of many ways of doing this. I'm sure there are excellent tried and tested XML parsers out there though. This code will print <code>Passed</code>:</p>

<pre><code>import re

line='''&lt; verdict time="1472654306.7" result_str="Passed" result="2"&gt;Generator run successfully&lt; /verdict&gt; &lt; verdict time="1472654306.7" result_str="Skipped" result="0" final="True"&gt;Testgenerator not active&lt; /verdict&gt;'''

p = re.compile(r'.*?result_str="(.*?)"')
match = p.match(line)
print(match.group(1))
</code></pre>

python xml string list split