java - Why is Swing Parser's handleText not handling nested tags? -


I need to replace some HTML text that has asked nested tags to decorate 'matches' with CSS attributes ( Such as Firefox search). I can not just convert to a simple position (if the user has searched for "IMG" for example), so I'm just trying to replace (rather than tag attributes) instead of body text.

I have a very simple HTML parser that I think should do this:

  last pattern pat = Pattern.compile (srch, Pattern.CASE_INSENSITIVE); Matcher M = Pat. Matter (output); If (m.find ()) {last stringbuffer rate = new stringbuffer (output.lampper () + 100); LastPos = 0; {New Parsegalator () Pars (new stringreader (output.testrein), new HTML decrykte.percrollback () {public zero handle text (four [data], int pauses) {ret.append (output.subSequence (lastPos, pos) ;;) ;);););); ();) Pos + data.length;}}, false); Ret.append (output. SubSequence (lastPos, output.length ())); Return writ; } Hold (exception e) {return output; }} Return output;  

My problem is, when I debug it, the handle text is being called with the text that contains the tag! It seems that this only one level is going deeper, someone knows why? To enable 'proper' behavior of nested tags, I need to do some simple thing for HTMLParser (not using it)?

PS - I thought it myself - see the answer below. In essence the answer is, if you pass it on HTML then it works fine, not before the HAL is saved. Ravindra! Hope this helps someone else.

  & lt; Span & gt; With example & lt; A href = "#" & gt; Nested & lt; / A & gt; & Lt; P & gt; More nesting victims & lt; / P & gt; & Lt; / Span & gt; & Lt ;! - It's all thrown together - & gt;  

I think using JDK6 on XP works fine for me. I wrapped my sample HTML with the head and body tag. I have three types of output:

a) Example with b) Nested c) Hunting of more nest

Here is the code I used:

 < Code> import java .io * Import Java.net *; Import javax.swing.text.html.parser *; Import javax.swing.text.html. *; Public class ParserKalbackTXT HTMLEditorKit.ParserCallback {Public Zero Handle Text (Four [Data], Intense Pauses {System.out.println (Data); } Public static zero chief (string [] args throws an exception {reader reader = miller (argues [0]); ParserCallbackText Parser = New ParserCallbackText (); New ParcelLugator () Pars (reader, parser, true); } Static Reader throws the GetReader (string uri) IOException {// Recover from the internet if (uri.startsWith ("http:")) {URLConnection conn = new URL (uri) .openConnection (); Return the new inputstream reader (conn.getInputStream ()); } // recover from the file. Return Other {New Filryers (Yuri); }}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -