Untitled
unknown
plain_text
a year ago
830 B
4
Indexable
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');
Editor is loading...
Leave a Comment