Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this instead.</p> <p>Edited to use the <a href="http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTMLEditorKit.html#read%28java.io.Reader,%20javax.swing.text.Document,%20int%29" rel="noreferrer"><code>read()</code></a> method of <a href="http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTMLEditorKit.html" rel="noreferrer"><code>HTMLEditorKit</code></a>.</p> <pre><code>import java.io.StringReader; import javax.swing.text.AttributeSet; import javax.swing.text.Element; import javax.swing.text.ElementIterator; import javax.swing.text.StyleConstants; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; public class NewMain { public static void main(String args[]) throws Exception { HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); htmlKit.read(new StringReader(text), htmlDoc, 0); // Parse ElementIterator iterator = new ElementIterator(htmlDoc); Element element; while ((element = iterator.next()) != null) { AttributeSet as = element.getAttributes(); Object name = as.getAttribute(StyleConstants.NameAttribute); if (name == HTML.Tag.DIV) { StringBuffer sb = new StringBuffer(); sb.append(name).append(": "); int count = element.getElementCount(); for (int i = 0; i &lt; count; i++) { Element child = element.getElement(i); int startOffset = child.getStartOffset(); int endOffset = child.getEndOffset(); int length = endOffset - startOffset; sb.append(htmlDoc.getText(startOffset, length)); } System.out.println(sb); } } } private static String text = "&lt;html&gt;\n" + "&lt;head&gt;\n" + "&lt;title&gt;pg_0001&lt;/title&gt;\n" + "\n" + "&lt;style type=\"text/css\"&gt;\n" + ".ft3{font-style:normal;font-weight:bold;font-size:11px;" + "font-family:Helvetica;color:#000000;}\n" + "&lt;/style&gt;\n" + "&lt;/head&gt;\n" + "&lt;body vlink=\"#FFFFFF\" link=\"#FFFFFF\" bgcolor=\"#ffffff\"&gt;\n" + "\n" + "\n" + "&lt;div style=\"position:absolute;top:597;left:252\"&gt;&lt;nobr&gt;&lt;span " + "class=\"ft3\"&gt;Christina Toth, Pharm. D.&lt;/span&gt;&lt;/nobr&gt;&lt;/div&gt;\n" + "\n" + "\n" + "&lt;/body&gt;\n" + "&lt;/html&gt;"; } </code></pre> <p>Console:</p> <pre>div: Christina Toth, Pharm. D.</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