Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>content.getText()</code> gives immediate text which is only useful fine with the leaf elements with text content. </p> <p>Trick is to use <a href="http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html#output%28java.util.List,%20java.io.OutputStream%29" rel="noreferrer"><code>org.jdom.output.XMLOutputter</code></a> ( with text mode <a href="http://www.jdom.org/docs/apidocs/org/jdom/output/Format.html#getCompactFormat%28%29" rel="noreferrer"><code>CompactFormat</code></a> )</p> <pre><code>public static void main(String[] args) throws Exception { SAXBuilder builder = new SAXBuilder(); String xmlFileName = "a.xml"; Document doc = builder.build(xmlFileName); Element root = doc.getRootElement(); Element overview = root.getChild("overview"); Element content = overview.getChild("content"); XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getCompactFormat()); //outp.setFormat(Format.getRawFormat()); //outp.setFormat(Format.getPrettyFormat()); //outp.getFormat().setTextMode(Format.TextMode.PRESERVE); StringWriter sw = new StringWriter(); outp.output(content.getContent(), sw); StringBuffer sb = sw.getBuffer(); System.out.println(sb.toString()); } </code></pre> <p><strong>Output</strong></p> <pre><code>For more info click&lt;a href="page.html"&gt;here&lt;/a&gt;&lt;p&gt;Learn more about the human body. Choose from a variety of Physiology (A&amp;amp;P) designed for complementary therapies.&amp;amp;#160; Online studies options are available.&lt;/p&gt; </code></pre> <p>Do explore other <a href="http://www.jdom.org/docs/apidocs/org/jdom/output/Format.html" rel="noreferrer">formatting</a> options and modify above code to your need.</p> <blockquote> <p>"Class to encapsulate XMLOutputter format options. Typical users can use the standard format configurations obtained by getRawFormat() (no whitespace changes), getPrettyFormat() (whitespace beautification), and getCompactFormat() (whitespace normalization). "</p> </blockquote>
    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. 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