Monday, 10 July 2017

Python SAX parser says XML file is not well-formed




I stripped some tags that I thought were unnecessary from an XML file. Now when I try to parse it, my SAX parser throws an error and says my file is not well-formed. However, I know every start tag has an end tag. The file's opening tag has a link to an XML schema. Could this be causing the trouble? If so, then how do I fix it?



Edit: I think I've found the problem. My character data contains "<" and ">" characters, presumably from html tags. After being parsed, these are converted to "<" and ">" characters, which seems to bother the SAX parser. Is there any way to prevent this from happening?


Answer



Does the sax parser not give you details about where it thinks it's not well-formed?



Have you tried loading the file into an XML editor and checking it there? Do other XML parsers accept it?



The schema shouldn't change whether or not the XML is well-formed or not; it may well change whether it's valid or not. See the wikipedia entry for XML well-formedness for a little bit more, or the XML specs for a lot more detail :)




EDIT: To represent "&" in text, you should escape it as &



So:



<


should be



&lt



(assuming you really want ampersand, l, t).


No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...