Выдираем элементы из XML конфига, предварительно слитого по tftp. Это код на момент самого начала изысканий, но думаю пригодится в будущем.
#!/usr/bin/perl
use XML::Twig;
my $catbuf = ''; #buffer, helps to format string, to make "table"
#my $itembu = '';
my $twig = new XML::Twig( TwigHandlers => {
"xos-configuration/xos-module-vlan/vlan/tag" => \&tag, #path to data in XML XOS config file
"xos-configuration/xos-module-vlan/vlan/name" => \&name,
#"xos-configuration/xos-module-eaps/eapsDomainMbrVlan/memberVlan" => \&name,
#"xos-configuration/xos-module-eaps/eapsDomainMbrVlan/domainName" => \&domain,
#"xos-configuration/xos-module-vlan/vlanPort/vlanName" => \&name, #path to data
#"xos-configuration/xos-module-vlan/vlanPort/taggedPorts" => \&ports,
});
$twig->parsefile( shift @ARGV );
# Vlan name and tag
sub name {
my( $tree, $elem ) =@_;
$catbuf = "" . $elem->text . " "; #make "table": vlan-name [tab] vlan-tag
}
sub tag {
my( $tree, $elem ) =@_;
$catbuf .= "" . $elem->text . "\n";
print $catbuf;
}
#-----------------------------
#sub domain {
# my( $tree, $elem ) =@_;
# $catbuf .= "" . $elem->text . "\n";
# print $catbuf;
#}
# Tagged ports data
#sub name {
# my( $tree, $elem ) =@_;
# $catbuf = "" . $elem->text . " ";
#}
#sub ports {
# my( $tree, $elem ) =@_;
# $catbuf .= "" . $elem->text . "\n";
# print $catbuf;
#}
use XML::Twig;
my $catbuf = ''; #buffer, helps to format string, to make "table"
#my $itembu = '';
my $twig = new XML::Twig( TwigHandlers => {
"xos-configuration/xos-module-vlan/vlan/tag" => \&tag, #path to data in XML XOS config file
"xos-configuration/xos-module-vlan/vlan/name" => \&name,
#"xos-configuration/xos-module-eaps/eapsDomainMbrVlan/memberVlan" => \&name,
#"xos-configuration/xos-module-eaps/eapsDomainMbrVlan/domainName" => \&domain,
#"xos-configuration/xos-module-vlan/vlanPort/vlanName" => \&name, #path to data
#"xos-configuration/xos-module-vlan/vlanPort/taggedPorts" => \&ports,
});
$twig->parsefile( shift @ARGV );
# Vlan name and tag
sub name {
my( $tree, $elem ) =@_;
$catbuf = "" . $elem->text . " "; #make "table": vlan-name [tab] vlan-tag
}
sub tag {
my( $tree, $elem ) =@_;
$catbuf .= "" . $elem->text . "\n";
print $catbuf;
}
#-----------------------------
#sub domain {
# my( $tree, $elem ) =@_;
# $catbuf .= "" . $elem->text . "\n";
# print $catbuf;
#}
# Tagged ports data
#sub name {
# my( $tree, $elem ) =@_;
# $catbuf = "" . $elem->text . " ";
#}
#sub ports {
# my( $tree, $elem ) =@_;
# $catbuf .= "" . $elem->text . "\n";
# print $catbuf;
#}
Комментариев нет:
Отправить комментарий