Untitled
Anonymous
plain_text
04/16/2024 7:49 PM
1.1 KB
14
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