• Tdom Tree Convert into arrays

    From eddy@21:1/5 to All on Thu Mar 30 09:12:26 2023
    I need to convert an XML file into arrays how that can look like ?

    i need than following information as an array
    <NXOpen.CAM.RoughTurning Name="ROUGH_OD_CYCLE" Tag="63001" Type="100" Subtype="510" Index="2">

    oper(ROUGH_PRIME_OD,UDEs,StartSet) "dwell"
    oper(ROUGH_PRIME_OD,UDEs,EndSet) "insert"

    oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,command_status) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_mode) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_value) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_text) "False"

    oper(ROUGH_PRIME_OD,UDEs,EndSet,insert,Instruction) "True"


    <?xml version="1.0" encoding="utf-8"?>
    <ONT Timestamp="638152743541369068" NXPart="smpl_sim09_5ax-trnmll_sinumerik_mm">
    <ProgramView>
    <NXOpen.CAM.NCGroup Name="NC_PROGRAM" Tag="63961" Type="121" Subtype="160">
    <NXOpen.CAM.NCGroup Name="NONE" Tag="63963" Type="112" Subtype="0" />
    <NXOpen.CAM.NCGroup Name="PROGRAM" Tag="63948" Type="121" Subtype="160">
    <NXOpen.CAM.NCGroup Name="TURNING" Tag="63928" Type="121" Subtype="160">
    <UDEs>
    <StartSet>
    <UDE Name="head">
    <Parameters>
    <UDE Name="command_status" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Active" StringText="" Point="" Vector="" />
    <UDE Name="head_name" ParameterActive="True" ParameterOptional="True" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="turn" Point="" Vector="" />
    </Parameters>
    </UDE>
    </StartSet>
    </UDEs>
    <NXOpen.CAM.RoughTurning Name="ROUGH_PRIME_OD" Tag="63000" Type="100" Subtype="510" Index="1"></NXOpen.CAM.RoughTurning>
    <NXOpen.CAM.RoughTurning Name="ROUGH_OD_CYCLE" Tag="63001" Type="100" Subtype="510" Index="2">
    <UDEs>
    <StartSet>
    <UDE Name="dwell">
    <Parameters>
    <UDE Name="command_status" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Active" StringText="" Point="" Vector="" />
    <UDE Name="delay_mode" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Seconds" StringText="" Point="" Vector="" />
    <UDE Name="delay_value" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="10" IntegerValue="0" OptionText="" StringText="" Point="" Vector="" />
    <UDE Name="delay_text" ParameterActive="False" ParameterOptional="True" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="" Point="" Vector="" />
    </Parameters>
    </UDE>
    </StartSet>
    <EndSet>
    <UDE Name="insert">
    <Parameters>
    <UDE Name="Instruction" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="ttt" Point="" Vector="" />
    </Parameters>
    </UDE>
    </EndSet>
    </UDEs>
    <Attributes>
    <Attribute Title="GENERATED ON" Type="String" Category="">NX 2212.3001 2023/03/24 16:29:43</Attribute>
    </Attributes>
    </NXOpen.CAM.RoughTurning>
    </NXOpen.CAM.NCGroup>
    </NXOpen.CAM.NCGroup>
    </NXOpen.CAM.NCGroup>
    </ProgramView>
    </ONT>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From D Groth@21:1/5 to eddy on Thu Mar 30 23:31:22 2023
    eddy schrieb am Donnerstag, 30. März 2023 um 18:12:29 UTC+2:
    I need to convert an XML file into arrays how that can look like ?

    i need than following information as an array
    <NXOpen.CAM.RoughTurning Name="ROUGH_OD_CYCLE" Tag="63001" Type="100" Subtype="510" Index="2">

    oper(ROUGH_PRIME_OD,UDEs,StartSet) "dwell"
    oper(ROUGH_PRIME_OD,UDEs,EndSet) "insert"

    oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,command_status) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_mode) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_value) "True" oper(ROUGH_PRIME_OD,UDEs,StartSet,dwell,delay_text) "False"

    oper(ROUGH_PRIME_OD,UDEs,EndSet,insert,Instruction) "True"


    <?xml version="1.0" encoding="utf-8"?>
    <ONT Timestamp="638152743541369068" NXPart="smpl_sim09_5ax-trnmll_sinumerik_mm">
    <ProgramView>
    <NXOpen.CAM.NCGroup Name="NC_PROGRAM" Tag="63961" Type="121" Subtype="160"> <NXOpen.CAM.NCGroup Name="NONE" Tag="63963" Type="112" Subtype="0" /> <NXOpen.CAM.NCGroup Name="PROGRAM" Tag="63948" Type="121" Subtype="160"> <NXOpen.CAM.NCGroup Name="TURNING" Tag="63928" Type="121" Subtype="160"> <UDEs>
    <StartSet>
    <UDE Name="head">
    <Parameters>
    <UDE Name="command_status" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Active" StringText="" Point="" Vector="" />
    <UDE Name="head_name" ParameterActive="True" ParameterOptional="True" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="turn" Point="" Vector="" />
    </Parameters>
    </UDE>
    </StartSet>
    </UDEs>
    <NXOpen.CAM.RoughTurning Name="ROUGH_PRIME_OD" Tag="63000" Type="100" Subtype="510" Index="1"></NXOpen.CAM.RoughTurning>
    <NXOpen.CAM.RoughTurning Name="ROUGH_OD_CYCLE" Tag="63001" Type="100" Subtype="510" Index="2">
    <UDEs>
    <StartSet>
    <UDE Name="dwell">
    <Parameters>
    <UDE Name="command_status" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Active" StringText="" Point="" Vector="" />
    <UDE Name="delay_mode" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="Seconds" StringText="" Point="" Vector="" />
    <UDE Name="delay_value" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="10" IntegerValue="0" OptionText="" StringText="" Point="" Vector="" />
    <UDE Name="delay_text" ParameterActive="False" ParameterOptional="True" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="" Point="" Vector="" />
    </Parameters>
    </UDE>
    </StartSet>
    <EndSet>
    <UDE Name="insert">
    <Parameters>
    <UDE Name="Instruction" ParameterActive="True" ParameterOptional="False" BooleanValue="False" DoubleValue="0" IntegerValue="0" OptionText="" StringText="ttt" Point="" Vector="" />
    </Parameters>
    </UDE>
    </EndSet>
    </UDEs>
    <Attributes>
    <Attribute Title="GENERATED ON" Type="String" Category="">NX 2212.3001 2023/03/24 16:29:43</Attribute>
    </Attributes>
    </NXOpen.CAM.RoughTurning>
    </NXOpen.CAM.NCGroup>
    </NXOpen.CAM.NCGroup>
    </NXOpen.CAM.NCGroup>
    </ProgramView>
    </ONT>

    If the structure on top is your array, I would guess there is no simple way. You selection of attributes is very arbitrary and they are in somehow mixed order. I suggest that you read https://wiki.tcl-lang.org/page/tDOM - there the first example. In
    short, you might construct an array by using the tdom selectNodes method for the parts you are interested and ignoring others.

    Hope this helps.
    Detlef

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to D Groth on Fri Mar 31 14:30:07 2023
    D Groth <[email protected]> wrote:
    eddy schrieb am Donnerstag, 30. März 2023 um 18:12:29 UTC+2:
    I need to convert an XML file into arrays how that can look like ?


    If the structure on top is your array, I would guess there is no
    simple way. You selection of attributes is very arbitrary and they
    are in somehow mixed order. I suggest that you read https://wiki.tcl-lang.org/page/tDOM - there the first example. In
    short, you might construct an array by using the tdom selectNodes
    method for the parts you are interested and ignoring others.

    Given the 'surgical' power of xpath queries to pluck data from an XML
    document, I wonder why the OP simply does not use selectNodes with the
    proper xpath statements for the data they desire. That would likely be
    better, and more maintainable, than trying to "convert to arrays".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Rich on Mon Apr 3 10:37:17 2023
    On 1/4/23 00:30, Rich wrote:
    D Groth <[email protected]> wrote:
    eddy schrieb am Donnerstag, 30. März 2023 um 18:12:29 UTC+2:
    I need to convert an XML file into arrays how that can look like ?


    If the structure on top is your array, I would guess there is no
    simple way. You selection of attributes is very arbitrary and they
    are in somehow mixed order. I suggest that you read
    https://wiki.tcl-lang.org/page/tDOM - there the first example. In
    short, you might construct an array by using the tdom selectNodes
    method for the parts you are interested and ignoring others.

    Given the 'surgical' power of xpath queries to pluck data from an XML document, I wonder why the OP simply does not use selectNodes with the
    proper xpath statements for the data they desire. That would likely be better, and more maintainable, than trying to "convert to arrays".

    Could this be any help?

    package require tdom

    proc run {file} {
    set status [list \
    dwell command_status \
    dwell delay_mode \
    dwell delay_value \
    dwell delay_text \
    insert Instruction ]
    set query {
    string(//*[@Name="$group"]//*[@Name="$name"]/@ParameterActive)
    }
    set doc [dom parse [tDOM::xmlReadFile $file]]
    set root [$doc documentElement]
    foreach {group name} $status {
    set ans [$root selectNodes [subst -nocommands $query]]
    puts "$group/$name = $ans"
    }
    }
    run x.xml

    outputs

    dwell/command_status = True
    dwell/delay_mode = True
    dwell/delay_value = True
    dwell/delay_text = False
    insert/Instruction = True

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From eddy@21:1/5 to Peter Dean on Tue Apr 4 00:31:59 2023
    Peter Dean schrieb am Montag, 3. April 2023 um 02:37:25 UTC+2:
    On 1/4/23 00:30, Rich wrote:
    D Groth <[email protected]> wrote:
    eddy schrieb am Donnerstag, 30. März 2023 um 18:12:29 UTC+2:
    I need to convert an XML file into arrays how that can look like ?


    If the structure on top is your array, I would guess there is no
    simple way. You selection of attributes is very arbitrary and they
    are in somehow mixed order. I suggest that you read
    https://wiki.tcl-lang.org/page/tDOM - there the first example. In
    short, you might construct an array by using the tdom selectNodes
    method for the parts you are interested and ignoring others.

    Given the 'surgical' power of xpath queries to pluck data from an XML document, I wonder why the OP simply does not use selectNodes with the proper xpath statements for the data they desire. That would likely be better, and more maintainable, than trying to "convert to arrays".
    Could this be any help?

    package require tdom

    proc run {file} {
    set status [list \
    dwell command_status \
    dwell delay_mode \
    dwell delay_value \
    dwell delay_text \
    insert Instruction ]
    set query {
    string(//*[@Name="$group"]//*[@Name="$name"]/@ParameterActive)
    }
    set doc [dom parse [tDOM::xmlReadFile $file]]
    set root [$doc documentElement]
    foreach {group name} $status {
    set ans [$root selectNodes [subst -nocommands $query]]
    puts "$group/$name = $ans"
    }
    }
    run x.xml

    outputs

    dwell/command_status = True
    dwell/delay_mode = True
    dwell/delay_value = True
    dwell/delay_text = False
    insert/Instruction = True


    Hey Peter,
    thanks a lot this it was what im looking for :)
    Working fine for me an i get the needed results.

    Regards
    Eddy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)