JSFiddle - React, Tailwind, and code Playground

by dshilkret

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XFA Field Extractor</title>
</head>
<body>
    <input type="file" id="xfaFile" />
    <button onclick="extractFields()">Extract Fields</button>
    <pre id="output"></pre>

    <script>
        function extractFields() {
            const fileInput = document.getElementById('xfaFile');
            const file = fileInput.files[0];
            if (!file) {
                alert('Please select an XFA file.');
                return;
            }

            const reader = new FileReader();
            reader.onload = function(event) {
                const xmlContent = event.target.result;
                const parser = new DOMParser();
                const xmlDoc = parser.parseFromString(xmlContent, 'application/xml');
                const fields = xmlDoc.getElementsByTagName('field');
                const fieldNames = [];

                for (let i = 0; i < fields.length; i++) {
                    const fieldName = fields[i].getAttribute('name');
                    if (fieldName) {
                        fieldNames.push(fieldName);
                    }
                }

                document.getElementById('output').textContent = fieldNames.join('\n');
            };

            reader.readAsText(file);
        }
    </script>
</body>
</html>