330 lines
9.6 KiB
JavaScript
330 lines
9.6 KiB
JavaScript
import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
|
|
|
|
const input = `
|
|
<PartInfo>
|
|
<Name>MD11_RECP_INHP_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_INHP_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86124 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86125 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_TRFC_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_TRFC_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86140 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86141 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_DATA_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_DATA_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86142 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86143 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_WPT_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_WPT_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86144 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86145 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_VORNDB_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_VORNDB_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86146 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86147 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_ARPT_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_ARPT_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86148 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86149 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_MAGTRU_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_MAGTRU_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86150 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86151 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_MAP_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_MAP_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86152 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86153 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_VOR_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_VOR_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86154 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86155 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_PLAN_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_PLAN_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86156 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86157 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_APPR_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_APPR_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86158 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86159 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_TCAS_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_TCAS_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86160 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86161 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_VOR1_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_VOR1_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86162 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86163 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_INCR_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_INCR_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86164 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86165 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_VOR2_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_VOR2_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86166 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86167 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_ADF1_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_ADF1_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86168 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86169 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_DECR_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_DECR_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86170 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86171 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
<PartInfo>
|
|
<Name>MD11_RECP_ADF2_BT</Name>
|
|
<AnimLength>10</AnimLength>
|
|
<Animation>
|
|
<Parameter>
|
|
<Code>(L:MD11_RECP_ADF2_BT, enum) 10 *</Code>
|
|
<Lag>100</Lag>
|
|
</Parameter>
|
|
</Animation>
|
|
<MouseRect>
|
|
<Cursor>HAND</Cursor>
|
|
<MouseFlags>LEFTSINGLE+LEFTRELEASE</MouseFlags>
|
|
<CallbackCode>(M:Event) 'LeftSingle' scmp 0 == if{ 86172 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 86173 (>L:CEVENT) }</CallbackCode>
|
|
</MouseRect>
|
|
</PartInfo>
|
|
`;
|
|
|
|
function convert(element) {
|
|
const codes = [
|
|
...element.MouseRect.CallbackCode.matchAll(/([\d]*)[\s]*\(>L:CEVENT\)/gm),
|
|
].map((m) => m[1]);
|
|
|
|
return {
|
|
"@_Name": "MD11_Button",
|
|
NODE_NAME: element.Name,
|
|
CODE_PRESS: `${codes[0]} (>L:CEVENT)`,
|
|
CODE_RELEASE: `${codes[1]} (>L:CEVENT)`,
|
|
};
|
|
}
|
|
|
|
const parser = new XMLParser({
|
|
ignoreAttributes: false,
|
|
});
|
|
let jObj = parser.parse(input);
|
|
|
|
const output = [];
|
|
|
|
if (Array.isArray(jObj.PartInfo)) {
|
|
jObj.PartInfo.forEach((element) => {
|
|
output.push(convert(element));
|
|
});
|
|
} else {
|
|
output.push(convert(jObj.PartInfo));
|
|
}
|
|
|
|
const builder = new XMLBuilder({
|
|
ignoreAttributes: false,
|
|
arrayNodeName: "UseTemplate",
|
|
format: true,
|
|
});
|
|
const xmlContent = builder.build(output);
|
|
|
|
console.log(xmlContent);
|