|
1 | 1 | import { createSignal, For, onMount } from "solid-js"; |
2 | 2 | import { updateScreener } from "../../api/screener"; |
3 | | -import { parseStringPromise } from "xml2js"; |
| 3 | +import { XMLParser } from "fast-xml-parser"; |
4 | 4 |
|
5 | 5 | async function getDecisionNames(dmnXmlString) { |
6 | 6 | try { |
7 | | - const result = await parseStringPromise(dmnXmlString, { |
8 | | - explicitArray: false, |
9 | | - tagNameProcessors: [(name) => name.replace(/^.*:/, "")], // remove namespace prefixes |
| 7 | + const parser = new XMLParser({ |
| 8 | + ignoreAttributes: false, |
| 9 | + attributeNamePrefix: "@_", |
| 10 | + removeNamespace: true, // This removes namespace prefixes |
10 | 11 | }); |
11 | 12 |
|
12 | | - // Now 'definitions' and 'decision' keys are accessible without prefixes |
13 | | - const definitions = result.definitions; |
| 13 | + const result = parser.parse(dmnXmlString); |
| 14 | + console.log(result); |
| 15 | + const definitions = result["dmn:definitions"]; |
14 | 16 | if (!definitions) return []; |
15 | 17 |
|
16 | | - let decisions = definitions.decision || []; |
| 18 | + let decisions = definitions["dmn:decision"] || []; |
17 | 19 | if (!Array.isArray(decisions)) decisions = [decisions]; |
18 | 20 |
|
19 | | - const decisionNames = decisions.map((d) => d.$.name); |
| 21 | + console.log("decisions"); |
| 22 | + console.log(decisions); |
| 23 | + |
| 24 | + const decisionNames = decisions |
| 25 | + .map((d) => d["@_name"]) |
| 26 | + .filter((name) => name); // Filter out undefined names |
| 27 | + console.log("decision names"); |
| 28 | + console.log(decisionNames); |
20 | 29 | return decisionNames; |
21 | 30 | } catch (err) { |
22 | 31 | console.error("Error parsing DMN XML:", err); |
|
0 commit comments