private void loadData(XMLStreamReader reader, Metadata pdfObjRToValues)
            throws XMLStreamException {
        //reader is at the "xfa:data" element
        //scrape the contents from the text containing nodes
        StringBuilder buffer = new StringBuilder();
        while (reader.hasNext()) {
            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 (buffer.length() > 0) {
                        String localName = reader.getLocalName();
                        pdfObjRToValues.add(localName, buffer.toString());
                        buffer.setLength(0);
                    }
                    if (XFA_DATA.equals(reader.getName())) {
                        return;
                    }
                    break;

            }
        }
    }
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