refactor appeal for new and resume
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// lib/forms/parseFormXml.js
|
||||
import xpath from "xpath";
|
||||
|
||||
/**
|
||||
* NOTE: Your current page uses DOMParser, which is available in the browser.
|
||||
* For SSR parsing you'd usually use xmldom or a similar package.
|
||||
*
|
||||
* This module supports BOTH:
|
||||
* - Browser: pass DOMParser output doc
|
||||
* - Server: if you later add xmldom, pass its doc here
|
||||
*/
|
||||
|
||||
export function getSectionCount(doc) {
|
||||
const tabs = xpath.select("/form/tabs/tab[*]", doc);
|
||||
return Array.isArray(tabs) ? tabs.length : 0;
|
||||
}
|
||||
|
||||
export function getTabTitles(doc) {
|
||||
// same XPath you had
|
||||
const titleAttrs = xpath.select(
|
||||
"//form/tabs/tab[*]/labels/label[@description]/@description",
|
||||
doc
|
||||
);
|
||||
|
||||
if (!Array.isArray(titleAttrs)) return [];
|
||||
// Attribute nodes differ by parser; be defensive:
|
||||
return titleAttrs
|
||||
.map((n) => (typeof n?.value === "string" ? n.value : n?.toString?.()))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
export function getTabs(doc) {
|
||||
const tabs = xpath.select("//form/tabs/tab[*]", doc);
|
||||
return Array.isArray(tabs) ? tabs : [];
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// lib/forms/readFormXml.js
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* Reads /data/formsxml/{appealtypes}.xml and normalises it.
|
||||
* Returns { xmlStr } or throws on missing file.
|
||||
*/
|
||||
export function readFormXml(appealtypes) {
|
||||
if (!appealtypes) throw new Error("readFormXml: appealtypes is required");
|
||||
|
||||
const configDirectory = path.resolve(process.cwd(), "data/formsxml");
|
||||
const filePath = path.join(configDirectory, `${appealtypes}.xml`);
|
||||
|
||||
let xmlStr = fs.readFileSync(filePath, "utf8");
|
||||
|
||||
// Keep existing normalisation behaviour
|
||||
xmlStr = xmlStr.replace(/\t/g, "");
|
||||
xmlStr = xmlStr.replace(/\n/g, "");
|
||||
xmlStr = xmlStr.replace(/> <"/g, "><");
|
||||
xmlStr = xmlStr.toString();
|
||||
|
||||
return { xmlStr, filePath };
|
||||
}
|
||||
Reference in New Issue
Block a user