I guess this is a newbie question, but anyway:

I want to read a XML file and add some to it. From the Xerces-C FAQ I
understand that this isn't implemented straight forward and that I can
use the code from the DOMCreate example.

Below is my modified DOMCreate example. I only added two lines, but
when I run it I only get "Aborted".

Please reply direct to me since I'm currently not on the mailinglist (yet...)


use strict;
# use blib;
use XML::Xerces;
use XML::Xerces::DOMParse;
use Getopt::Std;
use vars qw($opt_v $opt_n);

#
# Read and validate command line args
#

my $USAGE = "USAGE: $0 [-v][-n] file\n";

getopts ('vn') and ($#ARGV == 0)        or die "$USAGE";
-f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";

my $validate = $opt_v || 0;
my $namespace = $opt_n || 0;
my $file = $ARGV[0];


#
# Parse and print
#

my $file = $ARGV[0];
my $parser = XML::Xerces::DOMParser->new();
$parser->setDoNamespaces ($namespace);
$parser->setDoValidation ($validate);
$parser->setToCreateXMLDeclTypeNode(1);
my $ERROR_HANDLER = XML::Xerces::perlErrorHandler->new();
$ERROR_HANDLER->setWarningFunction(\&XML::Xerces::warning);
$ERROR_HANDLER->setErrorFunction(\&XML::Xerces::error);
$ERROR_HANDLER->setFatalErrorFunction(\&XML::Xerces::fatal_error);
$parser->setErrorHandler($ERROR_HANDLER);
$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
my $doc = $parser->getDocument ();

# My modification
my $foo = $doc->createElement ("bar");
$doc->appendChild ($foo);
# End of my modification

XML::Xerces::DOMParse::unformat ($doc);
XML::Xerces::DOMParse::format ($doc);
XML::Xerces::DOMParse::print (\*STDOUT, $doc);



__END__



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to