diff --git a/bun.lockb b/bun.lockb index d196283..2e03f24 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e1a44cd..48e3e62 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,12 @@ "@types/w3c-web-usb": "^1.0.10" }, "//dependencies": { - "crc-32": "crc32s are used in the gpt header calculations" + "crc-32": "crc32s are used in the gpt header calculations", + "fast-xml-parser": "parse XML to JS object, fast, works in browser and node" }, "dependencies": { - "crc-32": "^1.2.2" + "crc-32": "^1.2.2", + "fast-xml-parser": "^5.0.8" }, "//peerDependencies": { "typescript": "does type checking, generates JS bundles and type declarations for language servers" diff --git a/src/xml.js b/src/xml.js index e0b7f8c..ffab905 100644 --- a/src/xml.js +++ b/src/xml.js @@ -1,3 +1,5 @@ +import { XMLParser } from "fast-xml-parser"; + /** * @param {string} tagName * @param {Record} [attributes={}] @@ -5,12 +7,18 @@ */ export function toXml(tagName, attributes = {}) { const attrs = Object.entries(attributes).map(([key, value]) => `${key}="${value}"`).join(" "); - return `<${tagName}${attrs ? ` ${attrs}` : ''} />`; + return `<${tagName}${attrs ? ` ${attrs}` : ""} />`; } export class xmlParser { decoder = new TextDecoder(); - parser = new DOMParser(); + parser = new XMLParser({ + attributeNamePrefix: "", + htmlEntities: true, + ignoreAttributes: false, + processEntities: true, + trimValues: false, + }); /** * @param {Uint8Array} input @@ -18,7 +26,8 @@ export class xmlParser { */ * #parseXmlDocuments(input) { for (const xml of this.decoder.decode(input).split(" { }); }); - // TODO: unclear whether this scenario occurs - test.skip("parse multiple response documents", () => { + // unclear whether this scenario occurs + test("parse multiple response documents", () => { const xml = ` `; const result = parser.getResponse(encoder.encode(xml));