Untitled
unknown
plain_text
2 years ago
830 B
6
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