HP-UX CMGR A.02.01 Administrator's and Developer's Guide
37
my $dataNode =
XML::XPath::Node::Element->new("data");
my $textNode =
XML::XPath::Node::Text->new("hello world");
$dataNode->appendChild($textNode);
# add new XML to the exchange.xml file at $XPATH
$xmlp->addTagDataNode($XPATH, $tag, $dataNode);
}
# import
elsif ($op =~ /^import/) {
my $xmlp = $context->get_xmlIn();
my $xpath = $xmlp->get_xp();
# find all nodes that match $XPATH with $tag
my @tagList = $xmlp->readTagList($XPATH, $tag);
# for each found $XPATH Node
for my $r_tag (@tagList) {
my $node=$r_tag->{node};
# print the text under ./data
my $text=$xpath->findnodes_as_string(
'./data/text()', $node);
print $text . "\n";;
}
}
return ();
}
sub read_config
{
my ($file) = @_;
return "" if ! -e $file;
open (my $in, '<', $file)
or die "Error: Can't open $file for reading: $!\n";
return do { local $/; <$in> };
}
sub write_config
{
my ($file, $contents) = @_;
open my $out, '>', "$file"
or die "Error: couldn't open $file for writing: $!\n";
print {$out} $contents;
}
1;
Create a variable validation function,
Cmgr::My_check_vars::check_system(), that is referenced by the example
template:
#!/usr/bin/perl
package Cmgr::My_check_vars;
use strict;
use warnings;