Rocky_Mountain_Vending/.pnpm-store/v10/files/24/bb176da19f4cac9f33a8c23edac7c92e904dd3feafbdaa8b1ea6dab3550247719632b9cf351a455a6daceade625cab6d785e071a47c2b544af3dd156cec7ae
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

57 lines
2.1 KiB
Text

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),
};
}