template-saas/apps/backend/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.browser.js
rckrdmrd 50a821a415
Some checks failed
CI / Backend CI (push) Has been cancelled
CI / Frontend CI (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / CI Summary (push) Has been cancelled
[SIMCO-V38] feat: Actualizar a SIMCO v3.8.0
- HERENCIA-SIMCO.md actualizado con directivas v3.7 y v3.8
- Actualizaciones de configuracion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 08:53:08 -06:00

58 lines
2.1 KiB
JavaScript

let parser;
export function parseXML(xmlString) {
if (!parser) {
parser = new DOMParser();
}
const xmlDocument = parser.parseFromString(xmlString, "application/xml");
if (xmlDocument.getElementsByTagName("parsererror").length > 0) {
throw new Error("DOMParser XML parsing error.");
}
const xmlToObj = (node) => {
if (node.nodeType === Node.TEXT_NODE) {
if (node.textContent?.trim()) {
return node.textContent;
}
}
if (node.nodeType === Node.ELEMENT_NODE) {
const element = node;
if (element.attributes.length === 0 && element.childNodes.length === 0) {
return "";
}
const obj = {};
const attributes = Array.from(element.attributes);
for (const attr of attributes) {
obj[`${attr.name}`] = attr.value;
}
const childNodes = Array.from(element.childNodes);
for (const child of childNodes) {
const childResult = xmlToObj(child);
if (childResult != null) {
const childName = child.nodeName;
if (childNodes.length === 1 && attributes.length === 0 && childName === "#text") {
return childResult;
}
if (obj[childName]) {
if (Array.isArray(obj[childName])) {
obj[childName].push(childResult);
}
else {
obj[childName] = [obj[childName], childResult];
}
}
else {
obj[childName] = childResult;
}
}
else if (childNodes.length === 1 && attributes.length === 0) {
return element.textContent;
}
}
return obj;
}
return null;
};
return {
[xmlDocument.documentElement.nodeName]: xmlToObj(xmlDocument.documentElement),
};
}