Note that there are some explanatory texts on larger screens.

plurals
  1. PONekoHTML SAX fragment parsing
    primarykey
    data
    text
    <p>I'm trying to parse a simple fragment of HTML with NekoHTML : </p> <pre><code>&lt;h1&gt;This is a basic test&lt;/h1&gt; </code></pre> <p>To do so, I've set a <a href="http://nekohtml.sourceforge.net/faq.html#fragments" rel="nofollow">specific Neko feature</a> not to have any HTML, HEAD or BODY tag calling startElement(..) callback.</p> <p>Unfortunatly, it doesn't work for me.. I certainly missed something but can't figured out what it would be.</p> <p>Here is a very simple code to reproduce my problem :</p> <pre><code> public static class MyContentHandler implements ContentHandler { public void characters(char[] ch, int start, int length) throws SAXException { String text = String.valueOf(ch, start, length); System.out.println(text); } public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributes) throws SAXException { System.out.println(rawName); } public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException { System.out.println("end " + localName); } } </code></pre> <p>And the main() to launch a test :</p> <pre><code> public static void main(String[] args) throws SAXException, IOException { SAXParser saxReader = new SAXParser(); // set the feature like explained in documentation : http://nekohtml.sourceforge.net/faq.html#fragments saxReader.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment", true); saxReader.setContentHandler(new MyContentHandler()); saxReader.parse(new InputSource(new StringInputStream("&lt;h1&gt;This is a basic test&lt;/h1&gt;"))); } </code></pre> <p>The corresponding output :</p> <pre><code>HTML HEAD end HEAD BODY H1 This is a basic test end H1 end BODY end HTML </code></pre> <p>whereas I was expecting </p> <pre><code>H1 This is a basic test end H1 </code></pre> <p>Any idea ?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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