Skip to main content

parseXML

codebolt.outputparsers.parseXML(xmlString: string): Object
Parses XML string and returns a result object with success flag and parsed data.

Parameters

NameTypeDescription
xmlStringstringThe XML string to parse.

Response Structure

The method returns an object with the following structure:

Success Response

{
success: true,
parsed: {
rootElement: "<xml_content>"
}
}

Error Response

{
success: false,
parsed: undefined
}

Examples

Valid XML Parsing

const xmlData = '<root><item id="1">Test Item</item><item id="2">Another Item</item></root>';
const result = await codebolt.outputparsers.parseXML(xmlData);
console.log(result);
// Output: {
// success: true,
// parsed: {
// rootElement: '<root><item id="1">Test Item</item><item id="2">Another Item</item></root>'
// }
// }

Invalid XML Parsing

const invalidXml = 'not valid xml';
const result = await codebolt.outputparsers.parseXML(invalidXml);
console.log(result);
// Output: { success: false, parsed: undefined }