private void handleField(XMLStreamReader reader, Map<String, XFAField> fields)
            throws XMLStreamException {
        //reader is set to the field element
        String fieldName = findFirstAttributeValue(reader, "name");
        String pdfObjRef = "";
        String toolTip = "";
        while (reader.hasNext()) {
            switch (reader.next()) {
                case XMLStreamConstants.START_ELEMENT:
                    if ("toolTip".equals(reader.getName().getLocalPart())) {
                        toolTip = scrapeTextUntil(reader, reader.getName());
                    }
                    // add checkbutton, etcif (reader.getName().equals())
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    if (xfaTemplateMatcher.reset(reader.getName().getNamespaceURI()).find() &&
                            FIELD_LN.equals(reader.getName().getLocalPart())) {
                        if (fieldName != null) {
                            fields.put(fieldName, new XFAField(fieldName, toolTip, pdfObjRef));
                        }
                        return;
                    }
                    break;
                case XMLStreamConstants.PROCESSING_INSTRUCTION:
                    if ("PDF_OBJR".equals(reader.getPITarget())) {
                        pdfObjRef = reader.getPIData();
                    }
                    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