<DIV><BR>2009-07-20,"Stefan Behnel" <A href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</A>:<BR>&gt;<BR>&gt;qhlonline wrote:<BR>&gt;&gt; I have tried to alter the libxml2 source to add a callback telling the <BR>&gt;&gt; current position when an element parsed.<BR>&gt;<BR>&gt;Note that something that requires patching libxml2 will not make it into an<BR>&gt;lxml release.<BR>&gt;<BR>&gt;As you noted before, the parser context already provides this information<BR>&gt;at any time, not only when parsing elements. So adding a callback for it is<BR>&gt;not a sensible approach.<BR>&gt;<BR>&gt;I'm not even sure what this position means exactly. Is it (1) the byte<BR>&gt;position in the original (undecoded) data stream, (2) the byte position in<BR>&gt;the UTF-8 encoded parse stream, or (3) the character position in the XML<BR>&gt;stream?<BR>&gt;<BR>&gt;According to the libxml2 docs:<BR>&gt;<BR>&gt;        long nbChars : number of xmlChar processed<BR>&gt;<BR>&gt;This sounds like it's the second information. That would not be useful and<BR>&gt;shouldn't get exposed in lxml's API as it's rather error prone to rely on<BR>&gt;it: works for ASCII and UTF-8, obviously, may work for some other encodings<BR>&gt;depending on the data, but fails for most other streams. OTOH, the first<BR>&gt;and the third information /might/ be of interest, depending on your use<BR>&gt;case, but are not easily recovered from the information that the parser<BR>&gt;provides.<BR>&gt;<BR>&gt;<BR>&gt;&gt; I have nerver compile cython source before. Can any body give me some<BR>&gt;&gt; suggestion?<BR>&gt;<BR>&gt;If you just change lxml's sources, running setup.py will build it just as<BR>&gt;before. All you need to do is install Cython 0.11 or later.<BR>&gt;<BR>&gt;http://codespeak.net/lxml/build.html<BR>&gt;<BR>&gt;Stefan<BR></DIV>
<DIV>Now the key problem for me is I don't konw whether can I and how to change the lxml target parser defination to let it support&nbsp;my new callback&nbsp;in&nbsp;libxml2, I suspect that the Treebuilder class in Saxparser.pxi is the base class of target parser,because it support functions like 'start', 'end', 'close', &nbsp;'data', just like the target parser, But I am not sure, because this class seems to be used to bulid a ElmentTree or dom for parserd HTML document from its name and has no relationship with target parser. Am I&nbsp;steping the wrong place?</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>