2025-01-24 16:38:55 +01:00

187 lines
5.4 KiB
JavaScript

import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
const input = `
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_VHF1_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_VHF1_MIC_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{ 96256 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96257 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_VHF2_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_VHF2_MIC_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{ 96258 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96259 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_VHF3_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_VHF3_MIC_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{ 96260 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96261 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_HF1_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_HF1_MIC_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{ 96262 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96263 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_HF2_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_HF2_MIC_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{ 96264 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96265 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_SAT_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_SAT_MIC_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{ 96266 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96267 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_INT_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_INT_MIC_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{ 96268 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96269 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_CAB_MIC_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_CAB_MIC_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{ 96270 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96271 (&gt;L:CEVENT) }</CallbackCode>
</MouseRect>
</PartInfo>
<PartInfo>
<Name>MD11_OBS_AUDIO_PNL_IDENT_BT</Name>
<AnimLength>10</AnimLength>
<Animation>
<Parameter>
<Code>(L:MD11_OBS_AUDIO_PNL_IDENT_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{ 96320 (&gt;L:CEVENT) } (M:Event)
&apos;LeftRelease&apos; scmp 0 == if{ 96321 (&gt;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);