Parsing a PLC File for Strings

139 views Asked by At

I'm trying to figure out how to pull the data listed below as "<![CDATA['Sec']]>" or trying to extract "Sec" from it.

This is how i'm grabing the other variables.

    foreach (@L5Xfiles) {
    my $input="RSL_Export/"."$_";
    open(my $data, '<', $input) or die "Can't open < $input: $! \n";
    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_file($input);

    foreach my $tag ($doc ->findnodes('//Tag')) {
        my $atag = $tag->getAttribute('DataType');

        if (defined($atag) && $atag =~ /Timer_Tag/) {

            my $name=$tag->getAttribute('Name');
            my $out=$tag->findvalue('Data/Structure/StructureMember[@Name="SP"]/DataValueMember[@Name="Out"]/@Value');
            my $secmin=$tag->findvalue('Data/Structure/DataValueMember[@Name="UnitsSelect"]/@Value');
            my $min=$tag->findvalue('Data/Structure/StructureMember[@Name="SP"]/StructureMember[@Name="EU"]/DataValueMember[@Name="Min"]/@Value');
            my $max=$tag->findvalue('Data/Structure/StructureMember[@Name="SP"]/StructureMember[@Name="EU"]/DataValueMember[@Name="Max"]/@Value');
            my $name_L0 = $name;
            $name =~ s/_/\\_/g;
            $secmin =~ s/0/Sec/g;
            $secmin =~ s/1/Min/g;
            $timers{'TimerConfig'}{'TimerConfig'}{$name}=$out . " " . $secmin;
            my $RSLTAG = $name_L0;
            $TimerTestTags{$RSLTAG} ={RSLTAG=>$RSLTAG,L0=>$name_L0,L1=>'',L2=>'',L0_Type=>$atag,L1_Type=>'',L2_Type=>'',SP=>$out,Unit=>$secmin,Min=>$min,Max=>$max};    
        }   
    }
    }

This is a Snip From the file i'm using

<Tag Name="EDI_StartupTmr" TagType="Base" DataType="Timer_Tag" Constant="false" ExternalAccess="Read/Write">
<Data>00 00 00 00 00 00 00 00 90 5F 01 00 00 00 00 00 
00 00 5A 00 00 00 00 00 00 00 00 00 00 00 B4 42 
03 00 00 00 53 65 63 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
03 00 00 00 53 65 63 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 01 00 1E 00 00 00</Data>
<Data Format="Decorated">
<Structure DataType="Timer_Tag">
<DataValueMember Name="Acc" DataType="INT" Radix="Decimal" Value="0"/>
<StructureMember Name="Timer" DataType="TIMER">
<DataValueMember Name="PRE" DataType="DINT" Radix="Decimal" Value="90000"/>
<DataValueMember Name="ACC" DataType="DINT" Radix="Decimal" Value="0"/>
<DataValueMember Name="EN" DataType="BOOL" Value="0"/>
<DataValueMember Name="TT" DataType="BOOL" Value="0"/>
<DataValueMember Name="DN" DataType="BOOL" Value="0"/>
</StructureMember>
<DataValueMember Name="UnitsSelect" DataType="INT" Radix="Decimal" Value="0"/>
<DataValueMember Name="TmrRemain" DataType="INT" Radix="Decimal" Value="90"/>
<StructureMember Name="SP" DataType="Setpoint_Tag">
<DataValueMember Name="H" DataType="BOOL" Value="0"/>
<DataValueMember Name="N" DataType="BOOL" Value="0"/>
<DataValueMember Name="In" DataType="REAL" Radix="Float" Value="0.0"/>
<DataValueMember Name="Out" DataType="REAL" Radix="Float" Value="90.0"/>
<StructureMember Name="Unit" DataType="STRING">
<DataValueMember Name="LEN" DataType="DINT" Radix="Decimal" Value="3"/>
<DataValueMember Name="DATA" DataType="STRING" Radix="ASCII">
<![CDATA['Sec']]>
</DataValueMember>
</StructureMember>
</StructureMember>
</Structure>
</Data>
</Tag>
0

There are 0 answers