Search in sources :

Example 1 with XMLReaderSAX2Factory

use of org.jdom2.input.sax.XMLReaderSAX2Factory in project jspwiki by apache.

the class HtmlStringToWikiTranslator method htmlStringToElement.

/**
 * Use NekoHtml to parse HTML like well formed XHTML
 *
 * @param html
 * @return xhtml jdom root element (node "HTML")
 * @throws JDOMException
 * @throws IOException
 */
private Element htmlStringToElement(String html) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder(new XMLReaderSAX2Factory(true, CYBERNEKO_PARSER), null, null);
    Document doc = builder.build(new StringReader(html));
    Element element = doc.getRootElement();
    return element;
}
Also used : XMLReaderSAX2Factory(org.jdom2.input.sax.XMLReaderSAX2Factory) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) StringReader(java.io.StringReader) Document(org.jdom2.Document)

Example 2 with XMLReaderSAX2Factory

use of org.jdom2.input.sax.XMLReaderSAX2Factory in project cia by Hack23.

the class XmlAgentImpl method setNameSpaceOnXmlStream.

/**
 * Sets the name space on xml stream.
 *
 * @param in
 *            the in
 * @param nameSpace
 *            the name space
 * @return the source
 * @throws JDOMException
 *             the JDOM exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private static Source setNameSpaceOnXmlStream(final InputStream in, final String nameSpace) throws JDOMException, IOException {
    final SAXBuilder sb = new SAXBuilder(new XMLReaderSAX2Factory(false));
    final Document doc = sb.build(in);
    doc.getRootElement().setNamespace(Namespace.getNamespace(nameSpace));
    return new JDOMSource(doc);
}
Also used : XMLReaderSAX2Factory(org.jdom2.input.sax.XMLReaderSAX2Factory) SAXBuilder(org.jdom2.input.SAXBuilder) JDOMSource(org.jdom2.transform.JDOMSource) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)2 SAXBuilder (org.jdom2.input.SAXBuilder)2 XMLReaderSAX2Factory (org.jdom2.input.sax.XMLReaderSAX2Factory)2 StringReader (java.io.StringReader)1 Element (org.jdom2.Element)1 JDOMSource (org.jdom2.transform.JDOMSource)1