Skip to content Skip to sidebar Skip to footer

Lxml Xmlsyntaxerror: Namespace Default Prefix Was Not Found

I am using lxml to read my xml file. I am using a code something like below. It works just fine with lxml2.3 beta1, but with lxml2.3 it gives me zn xml syntax error as shown below.

Solution 1:

Ok, so I finally figured out what was going on. Following a good advice to clean up used elements, I was clearing up all the elements, including the root node. The root node is the one with the default namespace prefix which applies to all nodes within that root. Since I cleared off my root node, the default namespace prefix was no longer a part of the nsmap of its subelements. The previous versions seem to be forgiving of this but the latest version was more strict in this sense.

Not clearing the root element untill I was done reading the xml did the trick for me.

Solution 2:

default namespace problems most often arise when you are attempting xpath expression. For just parsing the stream as in your sample, 2.3.0 should work fine with an unnamed default namespace.

Perhaps you should post the smallest possible xml file that gives this error (line 545 is pretty deep into the file to have this error)

Post a Comment for "Lxml Xmlsyntaxerror: Namespace Default Prefix Was Not Found"