Line Number of a Start Tag
Hi, assume I have the following Python 3 code: ------------------------------ import io from lxml import etree source = """<?xml version="1.0"?> <article version="5.0" xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>...</title> <para>...</para> </article> """ tree = etree.parse(io.StringIO(source)) root = tree.getroot() print(root.sourceline) ------------------------------ When I run the above code, I get "4" as a result. This is a bit unexpected. It seems, root.sourceline returns the line number where the start tag _ends_. However, I need to get the line number where <article> _starts_ (here in this example "2"). How can I get the "starting" line number of a start tag? Thanks! -- Gruß/Regards, Thomas Schraitle
participants (2)
-
Stefan Behnel
-
Thomas Schraitle