Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
JavaScript XML libraries parse XML documents into objects or DOM trees and write XML back out. A streaming parser emits an event for each tag rather than loading the whole document into memory. These libraries let apps read feeds, sitemaps, and SOAP responses from services that return XML.
Popularity
saxes has the most monthly downloads in this comparison, at 617.8M.
export function runQuery(query: string, xmlStr: string): Element[] {
const dom = new DOMParser().parseFromString(xmlStr, MIME_TYPE.XML_TEXT);
let nodes: ReturnType<typeof xpathQuery>;
try {
// @ts-expect-error Missing Node properties are not needed. // https://github.com/xmldom/xmldom/issues/724 nodes = xpathQuery(query, dom);
} catch (err) {
// report a malformed query the same way drivers do instead of as an unknown server error. // messages such as 'Unknown function foo' tell the user what to fix, the generic one does not const reason = (err as Error).message;
const details = reason && reason !== GENERIC_XPATH_PARSE_ERROR ? ` (${reason})` : '';
throw new errors.InvalidSelectorError(`Invalid XPath selector: ${query}${details}`, err as Error);
}
// the xpath typings describe lib.dom nodes rather than xmldom ones, so this is the one place // where the two type worlds have to be bridged return nodes as unknown as Element[];
}
xml2js
Maps XML to JavaScript objects and builds XML from object data.
Downloads / mo
243.7M
Stars
5.0K
Last release
0.6.2
License
MIT
Strengths
Offers promise-based parsing.Use parseStringPromise in asynchronous XML loading workflows.
Builds attributes and text together.Use the object’s attribute and text keys when rebuilding XML.
Limitations
Round trips depend on settings.Keep defaults when exact object-to-XML round trips matter.
Parser reuse needs a reset.Create one parser per file or reset it between documents.
function runJsBased(xml: string, metodo: SchemaValidateMethod): Promise<SchemaValidationResult> {
return new Promise(async (resolve, reject) => {
const { basePath, schemaPath } = getSchema(metodo);
if (!schemaPath) {
reject(makeResult(false, metodo, '', [internalIssue(
`Schema XSD não encontrado para o método '${metodo}'. Verifique se o nome do método está correto.`,
)]));
return;
}
try {
const completeXSD = await xsdAssembler.assemble(schemaPath);
const xmlDoc = libxmljs.parseXml(xml);
const xsdDoc = libxmljs.parseXml(completeXSD, { baseUrl: `${basePath}/` });
const isValid = xmlDoc.validate(xsdDoc);
if (isValid) {
resolve(makeResult(true, metodo, schemaPath, []));
return;
}
const errors: SchemaValidationIssue[] = (xmlDoc.validationErrors || []).map((e: any) =>
humanizeIssue(String(e.message ?? e).trim(), e.line, e.column),
);
reject(makeResult(false, metodo, schemaPath, errors.length ? errors : [internalIssue('XML inválido (sem detalhes do validador).')]));
} catch (error: any) {
reject(makeResult(false, metodo, schemaPath, [internalIssue(String(error?.message ?? error))]));
}
});
}
FAQ
fast-xml-parser suits converting XML to JavaScript objects and back. xmldom suits code that needs a standard DOM to query and edit. saxes suits large documents that must stream.
fast-xml-parser parses XML into JavaScript objects and builds XML from objects. Its options control attributes, arrays, and value parsing.
xml2js maps XML to JavaScript objects and builds XML from object data. It wraps the sax parser in a callback and promise API.
Parse the XML into a JavaScript object with fast-xml-parser or xml-js, then pass the object to JSON.stringify.
A SAX parser reads XML as a stream and emits an event for each opening tag, text node, and closing tag. sax and saxes use this model for documents too large to hold in memory.
For coding agents
Found your XML library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.