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>
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.
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".
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
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 143:30:21 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,474 |