Note that there are some explanatory texts on larger screens.

plurals
  1. POElement to string in HTMLDocument
    primarykey
    data
    text
    <p>i have a Element object its a HTMLDocument object and i want to string value of this element.</p> <p>i want this result </p> Christina Toth, Pharm. D. <p>=======================</p> <p>plz see below code.</p> <pre><code>public static void main(String args[]) throws Exception { InputStream is = Nullsoft.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); HTMLEditorKit.Parser parser = new ParserDelegator(); HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0); parser.parse(br, callback, true); // Parse ElementIterator iterator = new ElementIterator(htmlDoc); Element element; while ((element = iterator.next()) != null) { AttributeSet attributes = element.getAttributes(); Object name = attributes.getAttribute(StyleConstants.NameAttribute); if ((name instanceof HTML.Tag) &amp;&amp; ((name == HTML.Tag.DIV) || (name == HTML.Tag.H2) || (name == HTML.Tag.H3))) { StringBuffer text = new StringBuffer(); int count = element.getElementCount(); for (int i = 0; i &lt; count; i++) { Element child = element.getElement(i); AttributeSet childAttributes = child.getAttributes(); // if (childAttributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.CONTENT) { int startOffset = child.getStartOffset(); int endOffset = child.getEndOffset(); int length = endOffset - startOffset; text.append(htmlDoc.getText(startOffset, length)); } } System.out.println(name + ": " + text.toString()); } } System.exit(0); } public static InputStream getInputStream() { 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;"; InputStream is = null; try { is = new ByteArrayInputStream(text.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return is; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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