I want to parse an XML file in python and assert some tag orders. I have started with ElementTree. Here is my code:
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
root = tree.getroot()
And here is the test.xml:
<a>
<b>
for (i=0; i<10; i++){
k++;
}
</b>
</a>
The problem is, the parser stucks at the for statement with the following error:
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 12
I need the parser to ignore the body of tags (ignoring anything comes inside the <b></b>). Is there a way to do so?
Thanks in advance.
Your XML markup is invalid XML markup!
You need to enclose the offending text inside a CDATA section.
http://www.w3schools.com/xml/xml_cdata.asp