<DIV><BR>2009-07-17,"Stefan Behnel" &lt;stefan_ml@behnel.de&gt; :<BR>&gt;<BR>&gt;qhlonline wrote:<BR>&gt;&gt; If there are some way for me to get the parsing context, and if I can<BR>&gt;&gt; access this structure directly, may be this problem can get solved.&nbsp; In<BR>&gt;&gt; libxml2 there is a defination of "struct _xmlParserCtxt". This structure<BR>&gt;&gt; have a member "long nbChars; " , It is just the "number of xmlChar<BR>&gt;&gt; processed" .<BR>&gt;<BR>&gt;You could subtype the XMLParser class in Cython. That's not trivial, since<BR>&gt;it's not exported at the C-API level. You'll have to redefine the class<BR>&gt;hierarchy in a separate lxml.etree.pxd file to do that. Note that you only<BR>&gt;need to access the _parser_context and (maybe) _push_parser_context. The<BR>&gt;other object type fields in the classes can be set to type "object" instead<BR>&gt;of their real type.<BR>&gt;<BR>&gt;But remember that the type isn't public. Future lxml versions may change<BR>&gt;it, which means that you will have to adapt your code.<BR>&gt;</DIV>
<DIV>I have changed the libxml2 code to add a new callback telling the current position when an element was seen. I think this can avoid the direct access to parser context. But I am now thinking of how to change target parser to let it access the newly defined callback on python level. I even did't know where to find the target related lxml source code. nor do I know whether&nbsp;my idea is feasble. Is target parser inherited from the TreeBuilder class? can It be changed? and how? I am in urgent need of more and deeper&nbsp;lxml source information.<BR>&gt;That said, I still do not understand why you need the character stream<BR>&gt;position for parsing. Could you elaborate on that?</DIV>
<DIV>Well, the position information is usefull. Some outside source of HTML&nbsp;document is declared in a seperate file, like &lt;style&gt; 'css' file. We&nbsp;may get&nbsp;the&nbsp;HTML document and its related&nbsp;source&nbsp;on net concurrently. But the outside&nbsp;source&nbsp;should&nbsp;be inserted in the proper position&nbsp;of HTML document in out application after parse. so the related tag position is usefull now.<BR>&gt;<BR>&gt;Stefan<BR>&gt;<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>