Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is certainly doable, but requires a little work. You could create a Visitor that keeps track of where it is in the tree and accumulates the text and instance offsets as it progresses. However, that solution could just as well be implemented by a SAX handler directly, which would be a lot faster.</p> <p>This should give something to start with:</p> <pre><code>public class Main extends DefaultHandler { StringBuilder buf = new StringBuilder(); boolean collecting = false; int ic = 0; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (localName.equals("sentence")) { System.out.printf("s.id=%s\n", attributes.getValue("id")); collecting = true; buf.setLength(0); ic = 0; } else if (localName.equals("instance")) { ++ic; System.out.printf("i%d.id=%s\n", ic, attributes.getValue("id")); System.out.printf("i%d.start=%s\n", ic, buf.length()); } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (localName.equals("sentence")) { collecting = false; System.out.printf("s.text=%s\n", buf.toString()); } else if (localName.equals("instance")) { System.out.printf("i%d.end=%s\n", ic, buf.length()); } } @Override public void characters(char[] ch, int start, int length) throws SAXException { if (collecting) { buf.append(ch, start, length); } } public static void main(String[] args) throws Exception { SAXParserFactory f = SAXParserFactory.newInstance(); f.setNamespaceAware(true); f.newSAXParser().parse(Main.class.getResourceAsStream("data.xml"), new Main()); } } </code></pre>
    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. 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