private void scrapeTextUntil(XMLStreamReader reader, XHTMLContentHandler xhtml,
                                 QName endElement) throws XMLStreamException, SAXException {
        StringBuilder buffer = new StringBuilder();
        boolean keepGoing = true;
        while (reader.hasNext() && keepGoing) {
            switch (reader.next()) {
                case XMLStreamConstants.START_ELEMENT:
                    break;
                case XMLStreamConstants.CHARACTERS:
                    int start = reader.getTextStart();
                    int length = reader.getTextLength();
                    buffer.append(reader.getTextCharacters(), start, length);
                    break;

                case XMLStreamConstants.CDATA:
                    start = reader.getTextStart();
                    length = reader.getTextLength();
                    buffer.append(reader.getTextCharacters(), start, length);
                    break;

                case (XMLStreamConstants.END_ELEMENT):
                    if (reader.getName().equals(endElement)) {
                        keepGoing = false;
                    } else if ("p".equals(reader.getName().getLocalPart())) {
                        xhtml.element("p", buffer.toString());
                        buffer.setLength(0);
                    }
                    break;
            }
        }
        String remainder = buffer.toString();
        if (!remainder.isBlank()) {
            xhtml.element("p", remainder);
        }
    }
This class offers an initial capability to
scrape text containing elements out of XFA, and
it tries to link fields with values.
<p>
Some areas for improvement:
<ol>
    <li>convert this to 2 lines of XPath</li>
    <li>handle metadata stored in &lt;desc&gt; section (govdocs1: 754282.pdf, 982106.pdf)</li>
    <li>handle pdf metadata (access permissions, etc.) in &lt;pdf&gt; element</li>
    <li>extract different types of uris as metadata</li>
    <li>add extraction of &lt;image&gt; data (govdocs1: 754282.pdf)</li>
    <li>add computation of traversal order for fields</li>
    <li>figure out when text extracted from xfa fields is duplicative of that
    extracted from the rest of the pdf...and do this efficiently and quickly</li>
    <li>avoid duplication with &lt;speak&gt; and &lt;tooltip&gt; elements</li>
</ol>
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/XFAExtractor.java