Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a stream parser, so as it parses it tells you what it hits. You should extend <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/text/html/parser/DocumentParser.html" rel="nofollow noreferrer"><code>HTMLEditorKit.ParserCallback</code></a> with some class (I'll call it <code>Parser</code>), then override the methods you care about.</p> <p>I believe it only works for "the html dtd in swing" (see <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/text/html/parser/DocumentParser.html" rel="nofollow noreferrer">here</a>). If you're doing anything more complicated recommend you instead use an external Java HTML parsing library, such as one of <a href="https://stackoverflow.com/questions/26638/what-html-parsing-libraries-do-you-recommend-in-java">the ones</a> I linked to before.</p> <p>Here's the basic code (<a href="http://ideone.com/pC4dy" rel="nofollow noreferrer">demo</a>):</p> <pre><code>import javax.swing.text.html.parser.*; import javax.swing.text.html.*; import javax.swing.text.*; import java.io.*; class Parser extends HTMLEditorKit.ParserCallback { private boolean inTD = false; public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) { if(t.equals(HTML.Tag.TD)) { inTD = true; } } public void handleEndTag(HTML.Tag t, int pos) { if(t.equals(HTML.Tag.TD)) { inTD = false; } } public void handleText(char[] data, int pos) { if(inTD) { doSomethingWith(data); } } public void doSomethingWith(char[] data) { System.out.println(data); } } class HtmlTester { public static void main (String[] args) throws java.lang.Exception { ParserDelegator pd = new ParserDelegator(); pd.parse(new BufferedReader(new InputStreamReader(System.in)), new Parser(), false); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload