Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
830 B
1
Indexable
Never
const fs = require('fs');
const parser = require('fast-xml-parser');

function searchGroupByText(xmlFilePath, searchText) {
    // Read XML file
    const xmlData = fs.readFileSync(xmlFilePath, 'utf8');
    
    // Parse XML data
    const jsonData = parser.parse(xmlData);
    
    // Define a function to recursively search for the text in JSON
    function search(json, text) {
        for (const key in json) {
            if (typeof json[key] === 'object') {
                search(json[key], text);
            } else if (typeof json[key] === 'string' && json[key].includes(text)) {
                console.log('Found in group:', json);
                break;
            }
        }
    }
    
    // Start the search
    search(jsonData, searchText);
}

// Example usage
searchGroupByText('example.xml', 'specific text');
Leave a Comment