<DIV>Stefan Behnel" &lt;stefan_ml@behnel.de&gt;<BR>&gt;<BR>&gt;qhlonline wrote:<BR>&gt;&gt; Hi, all I am parsing html files with lxml target parser, now I wan't to<BR>&gt;&gt; know when I have reached some HTML tag, how can I know the position of<BR>&gt;&gt; the HTML document I am parsing?<BR>&gt;<BR>&gt;These are two different requirements. Do you really need the line/character<BR>&gt;information here? Isn't the structural position enough?<BR>&gt;</DIV>
<DIV>I have to know the real parsing&nbsp;position when some special tags found by target parser. Is the&nbsp;'structural position ' means information about&nbsp;which line and which column, like that in Parsing Error Report? I think they are helpless in compute the parsing stream length.&nbsp;In libxml2 source file SAX2.c there is an&nbsp;callback interface (charactersSAXFunc) for character event:</DIV>
<DIV>&nbsp;&nbsp;&nbsp; hdlr-&gt;characters = xmlSAX2Characters&nbsp;&nbsp;</DIV>
<DIV>The event handler&nbsp;has a 'len' parameter which tells current parsed&nbsp;HTML stream&nbsp;length. and I noticed that lxml source Saxparser.pxi there is a function defination:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cdef void _handleSaxData(void* ctxt, char* c_data, int data_len) with gil:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;It works just&nbsp;as processer of the sax.character event. How can I change the lxml source code of target parser to add sax.character event processing to it with 'data_len' parameter? Not the default 'data' function in target parser of couse, It has no parameter like 'data_len' and its 'data' parameter is only the text between&nbsp;an element, not the&nbsp;whole parsed string.<BR>&gt;&gt; Is there any callbacks in target parser<BR>&gt;&gt; who can tell me the total stream length I have parsed?<BR>&gt;<BR>&gt;Not that I know of. Same as in ElementTree, I'd say.<BR>&gt;<BR>&gt;Stefan<BR></DIV><br><!-- footer --><br><span title="neteasefooter"/><hr/>
<a href="http://count.mail.163.com/redirect/footer.htm?f=http://gouwu.youdao.com">200万种商品,最低价格,疯狂诱惑你</a>
</span>