[lxml-dev] how to get line,col position
Stefan Behnel
stefan_ml at behnel.de
Thu May 7 20:54:25 CEST 2009
Hi,
Mary Lei wrote:
> Stefan Behnel wrote:
>> http://bugzilla.gnome.org/show_bug.cgi?id=580705
>>
>> Note that this bug has a patch associated to it, which you can apply to
>> libxml2 to get what you want.
> Where can I locate this patch ?
You click on the link above, and on that page, click on the link where it
says "patch here".
>> Otherwise, for parsing XHTML you should use the XML parser anyway, which
>> will track line numbers correctly.
> Using the XML parser, results in error to load the dtd from network
> lxml.etree.XMLSyntaxError: Attempt to load network entity
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
You can enable network access with the "no_network=False" option. However,
it's better to use a catalog to let libxml2 look up the DTD locally.
http://www.xmlsoft.org/catalog.html
> I dont really want to load each time so I downloaded a copy with the
> entities and decide to use etree.dtd.validate to validate it instead.
> But as
> mentioned, this does not give the line,col info.
>
> If I use the XMLParser, I have an issue with
> lxml.etree.XMLSyntaxError: Entity 'nbsp' not defined, line 24, column 13
>
> but my xhtml has a DTD specified.
Did you load the DTD when parsing the file? This is not done automatically.
See the XMLParser documentation, it has a "load_dtd" option IIRC.
Stefan
More information about the lxml-dev
mailing list