187 lines
5.4 KiB
JavaScript
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) 'LeftSingle' scmp 0 == if{ 96256 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96257 (>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) 'LeftSingle' scmp 0 == if{ 96258 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96259 (>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) 'LeftSingle' scmp 0 == if{ 96260 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96261 (>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) 'LeftSingle' scmp 0 == if{ 96262 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96263 (>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) 'LeftSingle' scmp 0 == if{ 96264 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96265 (>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) 'LeftSingle' scmp 0 == if{ 96266 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96267 (>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) 'LeftSingle' scmp 0 == if{ 96268 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96269 (>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) 'LeftSingle' scmp 0 == if{ 96270 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96271 (>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) 'LeftSingle' scmp 0 == if{ 96320 (>L:CEVENT) } (M:Event)
|
|
'LeftRelease' scmp 0 == if{ 96321 (>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);
|