2025-01-23 04:05:37 +01:00

164 lines
4.7 KiB
JavaScript

import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
const input = `
<PartInfo>
<Name>MD11_OVHD_FLTCTL_UYDA_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_UYDA_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90390 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90391 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_UYDB_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_UYDB_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90392 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90393 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_LYDA_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_LYDA_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90394 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90395 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_LYDB_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_LYDB_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90396 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90397 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_LLO_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_LLO_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90398 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90399 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_LLI_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_LLI_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90400 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90401 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_RLI_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_RLI_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90402 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90403 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OVHD_FLTCTL_RLO_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OVHD_FLTCTL_RLO_BT, enum) 10 *</Code>
<Lag>100</Lag>
</Parameter>
</Animation>
<MouseRect>
<Cursor>HAND</Cursor>
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
<CallbackCode>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 90404 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 90405 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
`;
const parser = new XMLParser({
ignoreAttributes: false,
});
let jObj = parser.parse(input);
const output = [];
jObj.PartInfo.forEach((element) => {
const codes = [
...element.MouseRect.CallbackCode.matchAll(/([\d]*)[\s]*\(>L:CEVENT\)/gm),
].map((m) => m[1]);
const obj = {
"@_Name": "MD11_Button",
NODE_NAME: element.Name,
CODE_PRESS: `${codes[0]} (>L:CEVENT)`,
CODE_RELEASE: `${codes[1]} (>L:CEVENT)`,
};
output.push(obj);
});
const builder = new XMLBuilder({
ignoreAttributes: false,
arrayNodeName: "UseTemplate",
format: true,
});
const xmlContent = builder.build(output);
console.log(xmlContent);