164 lines
4.7 KiB
JavaScript
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) 'LeftSingle' scmp 0 == if{ 90390 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90391 (>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) 'LeftSingle' scmp 0 == if{ 90392 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90393 (>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) 'LeftSingle' scmp 0 == if{ 90394 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90395 (>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) 'LeftSingle' scmp 0 == if{ 90396 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90397 (>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) 'LeftSingle' scmp 0 == if{ 90398 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90399 (>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) 'LeftSingle' scmp 0 == if{ 90400 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90401 (>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) 'LeftSingle' scmp 0 == if{ 90402 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90403 (>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) 'LeftSingle' scmp 0 == if{ 90404 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 90405 (>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);
|