In general, you are not . Parsing XML / HTML is quite complicated without trying to do it briefly, and although you can hack a solution that succeeds with a limited subset of XML, it will eventually break.
, XML-, , ?
, XML- awk, , XML awk, " ", ". , , , , - Perl, XML:: Simple ( ) - XML.
, , , XML. XML , :
<netlist>
<net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</netlist>
, XML , XML , , awk one-liner, "" "XML", XML .
, Perl script, :
use strict;
use warnings;
use XML::Simple;
sub usage {
die "Usage: $0 [NetName] ([attr])\n";
}
my $file = XMLin("file.xml", KeyAttr => { net => 'NetName' });
usage() if @ARGV == 0;
exists $file->{net}{$ARGV[0]}
or die "$ARGV[0] does not exist.\n";
if(@ARGV == 2) {
exists $file->{net}{$ARGV[0]}{$ARGV[1]}
or die "NetName $ARGV[0] does not have attribute $ARGV[1].\n";
print "$file->{net}{$ARGV[0]}{$ARGV[1]}.\n";
} elsif(@ARGV == 1) {
print "$ARGV[0]:\n";
print " $_ = $file->{net}{$ARGV[0]}{$_}\n"
for keys %{ $file->{net}{$ARGV[0]} };
} else {
usage();
}
script 1 2 . - 'NetName', , - , . , 'NetName'.