Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications
with XML.
####
Galos, Mike
Visual Studio 7: A Comprehensive Guide
Computer
49.95
2001-04-16
Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.
####
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $xmlParser = XML::Twig->new();
# Fetch the new books to add to the catalog
my $new_items = fetch_xml('new_items.xml');
my @add;
for my $book ($new_items->root->children('book')) {
push @add, $book->copy();
}
print scalar(@add), " new books to add to the catalog!\n";
# Add the books to the catalog
my $cur_catalog = fetch_xml('current_catalog.xml');
for my $book (@add) {
# Each book will be added after the last book in the catalog
$book->paste(last_child => $cur_catalog->root);
}
# Now dump our current catalog
$cur_catalog->flush( \*STDERR, pretty_print=>'indented' );
sub fetch_xml {
my $fname = shift;
my $txt = do {
open my $FH, '<', $fname or die "$fname: $!";
local $/;
<$FH>;
};
$xmlParser->parse($txt);
return $xmlParser;
}
####
$ perl ex_XML_merge_twig.pl
1 new books to add to the catalog!
Galos, Mike
Visual Studio 7: A Comprehensive Guide
Computer
49.95
2001-04-16
Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.
Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications
with XML.