/** * This will handle printing out an <code>{@link * Element}</code>'s content only, not including its tag, and attributes. * This can be useful for printing the content of an element that contains * HTML, like "<description>JDOM is * <b>fun>!</description>". * <p> * <b>Warning</b>: a String is Unicode, which may not match the outputter's * specified encoding. * * @param element * <code>Element</code> to output. * @return the input content formatted as an XML String. * @throws NullPointerException * if the specified content is null. */ public final String outputElementContentString(Element element) { StringWriter out = new StringWriter(); try { outputElementContent(element, out); // output() flushes } catch (IOException e) { // swallow - will never happen. } return out.toString(); }
/** * This will handle printing out an <code>{@link * Element}</code>'s content only, not including its tag, and attributes. * This can be useful for printing the content of an element that contains * HTML, like "<description>JDOM is * <b>fun>!</description>". * * @param element * <code>Element</code> to output. * @param out * <code>OutputStream</code> to use. * @throws IOException * if there's any problem writing. * @throws NullPointerException * if the specified content is null. */ public final void outputElementContent(Element element, OutputStream out) throws IOException { outputElementContent(element, makeWriter(out, myFormat)); }
/** * {@inheritDoc} */ public String getString() throws IOException { m_document.setContext( m_context ); CustomXMLOutputProcessor processor = new CustomXMLOutputProcessor(); XMLOutputter output = new XMLOutputter(processor); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); String result = out.toString(); return result; } }
/** * {@inheritDoc} */ public String getString() throws IOException { Element rootElement = m_document.getRootElement(); processChildren( rootElement ); m_document.setContext( m_context ); XMLOutputter output = new XMLOutputter(); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); return out.toString(); } }