{"record":{"id":"b2aa778d8306f41e","repo":"DayuanJiang/next-ai-draw-io","slug":"no-diagram-element-found","errorCode":null,"errorMessage":"No diagram element found","messagePattern":"No diagram element found","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/utils.ts","lineNumber":1707,"sourceCode":"\n        if (!encodedContent) {\n            throw new Error(\"SVG element does not have a 'content' attribute.\")\n        }\n\n        // 3. Decode HTML entities (using a minimal function)\n        function decodeHtmlEntities(str: string) {\n            const textarea = document.createElement(\"textarea\") // Use built-in element\n            textarea.innerHTML = str\n            return textarea.value\n        }\n        const xmlContent = decodeHtmlEntities(encodedContent)\n\n        // 4. Parse the XML content\n        const xmlDoc = parser.parseFromString(xmlContent, \"text/xml\")\n        const diagramElement = xmlDoc.querySelector(\"diagram\")\n\n        if (!diagramElement) {\n            throw new Error(\"No diagram element found\")\n        }\n        // 5. Extract base64 encoded data\n        const base64EncodedData = diagramElement.textContent\n\n        if (!base64EncodedData) {\n            throw new Error(\"No encoded data found in the diagram element\")\n        }\n\n        // 6. Decode base64 data\n        const binaryString = atob(base64EncodedData)\n\n        // 7. Convert binary string to Uint8Array\n        const len = binaryString.length\n        const bytes = new Uint8Array(len)\n        for (let i = 0; i < len; i++) {\n            bytes[i] = binaryString.charCodeAt(i)\n        }\n","sourceCodeStart":1689,"sourceCodeEnd":1725,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/utils.ts#L1689-L1725","documentation":"After HTML-entity-decoding the SVG's content attribute and parsing it as XML, no <diagram> element was found. The embedded content is expected to be a draw.io <mxfile> containing one or more <diagram> elements. This means the decoded payload is XML but not draw.io diagram XML — the content attribute held something else.","triggerScenarios":"An SVG whose content attribute contains arbitrary embedded XML (metadata, foreign tool's format), entity decoding that failed or double-decoded and corrupted the markup, or a truncated content attribute.","commonSituations":"Third-party tools that reuse a 'content' attribute on <svg> for their own payload; hand-crafted SVGs mimicking draw.io's format; partially transferred files where the attribute got clipped.","solutions":["Decode the content attribute yourself and inspect what XML it actually contains","Verify the decoded root element is <mxfile> (or directly <mxGraphModel> for single-diagram files) and wrap accordingly","Re-export the diagram from draw.io to get a canonical embedded payload","If entity decoding is the culprit, ensure the payload wasn't already decoded upstream"],"exampleFix":"// before\nextractDiagramFromSvg(dataUri) // content attr holds non-drawio XML\n\n// after: normalize the payload first\nconst inner = decodeHtmlEntities(svgEl.getAttribute('content'))\nconst wrapped = `<mxfile><diagram>${inner}</diagram></mxfile>` // only if inner is mxGraphModel","handlingStrategy":"validation","validationCode":"const xml = decodeEntities(svgEl.getAttribute('content')!)\nconst parsed = new DOMParser().parseFromString(xml, 'text/xml')\nif (parsed.querySelector('parsererror') || !parsed.querySelector('diagram')) throw new Error('embedded content is not drawio mxfile xml')","typeGuard":"function isDrawioEmbeddedXml(doc: Document): boolean {\n  return Boolean(doc.querySelector('mxfile > diagram'))\n}","tryCatchPattern":"try { extract(dataUri) } catch (e) { if ((e as Error).message === 'No diagram element found') throw new Error('svg content attribute holds non-drawio XML; inspect it manually') }","preventionTips":["Only feed draw.io-exported editable SVGs to the extractor","Inspect the decoded content attribute when integrating new SVG sources","Pre-validate the decoded root is <mxfile>"],"tags":["drawio","xml","parsing","embedded-content"],"backgroundTag":"unexpected-payload-structure","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}