jasons 01/03/26 16:37:40
Added: sources/xerces-p DOMCount.xml DOMCreate.xml DOMPrint.xml
readme.ced samples.xml
Log:
Added the new files for xerces-p
Revision Changes Path
1.1 xml-site/sources/xerces-p/DOMCount.xml
Index: DOMCount.xml
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
<s1 title="DOMCount.pl">
<source><![CDATA[
use strict;
use XML::Xerces;
use Getopt::Std;
#
# Read and validate command line args
#
my $USAGE = "USAGE: $0 [-v][-n] file\n";
my $VERSION = q[$Id: DOMCount.xml,v 1.1 2001/03/27 00:37:39 jasons Exp $];
getopts ('vn') and ($#ARGV == 0) or die "$USAGE";
-f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
my $validate = $::opt_v;
my $namespace = $::opt_n;
my $file = $ARGV[0];
#
# Count the nodes
#
my $parser = XML::Xerces::DOMParser->new();
$parser->setDoValidation ($validate);
$parser->setDoNamespaces ($namespace);
my $error_handler = new XML::Xerces::perlErrorHandler;
$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 $element_count = $doc->getElementsByTagName("*")->getLength();
print "$file: ($element_count elems)\n";
]]></source>
</s1>
1.1 xml-site/sources/xerces-p/DOMCreate.xml
Index: DOMCreate.xml
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
<s1 title="DOMCreate.pl">
<source><![CDATA[
use strict;
use XML::Xerces;
use XML::Xerces::DOMParse;
#
# create a document
#
my $doc = XML::Xerces::DOM_Document::createDocument ();
my $root = $doc->createElement ("contributors");
$doc->appendChild ($root);
$root->appendChild(CreatePerson(
$doc,
'Mike Pogue',
'manager',
'[EMAIL PROTECTED]'
));
$root->appendChild(CreatePerson(
$doc,
'Tom Watson',
'developer',
'[EMAIL PROTECTED]'
));
$root->appendChild(CreatePerson(
$doc,
'Susan Hardenbrook',
'tech writer',
'[EMAIL PROTECTED]'
));
$XML::Xerces::DOMParse::INDENT = " ";
XML::Xerces::DOMParse::format ($doc);
XML::Xerces::DOMParse::print (\*STDOUT, $doc);
#################################################################
# routines to create the document
# no magic here ... they just organize many DOM calls
#################################################################
sub CreatePerson {
my ($doc, $name, $role, $email) = @_;
my $person = $doc->createElement ("person");
&SetName ($doc, $person, $name);
&SetEmail ($doc, $person, $email);
$person->setAttribute ("Role", $role);
return $person;
}
sub SetName {
my ($doc, $person, $nameText) = @_;
my $nameNode = $doc->createElement ("name");
my $nameTextNode = $doc->createTextNode ($nameText);
$nameNode->appendChild ($nameTextNode);
$person->appendChild ($nameNode);
}
sub SetEmail {
my ($doc, $person, $emailText) = @_;
my $emailNode = $doc->createElement ("email");
my $emailTextNode = $doc->createTextNode ($emailText);
$emailNode->appendChild ($emailTextNode);
$person->appendChild ($emailNode);
}
]]></source>
</s1>
1.1 xml-site/sources/xerces-p/DOMPrint.xml
Index: DOMPrint.xml
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
<s1 title="DOMPrint.pl">
<source><![CDATA[
use strict;
use XML::Xerces;
use XML::Xerces::DOMParse;
use Getopt::Std;
#
# 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;
my $namespace = $::opt_n;
my $file = $ARGV[0];
#
# Parse and print
#
my $file = $ARGV[0];
my $parser = XML::Xerces::DOMParser->new();
$parser->setDoNamespaces ($namespace);
$parser->setDoValidation ($validate);
$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
my $doc = $parser->getDocument ();
XML::Xerces::DOMParse::unformat ($doc);
XML::Xerces::DOMParse::format ($doc);
XML::Xerces::DOMParse::print (\*STDOUT, $doc);
]]></source>
</s1>
1.1 xml-site/sources/xerces-p/readme.ced
Index: readme.ced
===================================================================
;;; This file was created by psgml on Mon Mar 26 15:12:04 2001
(sgml-saved-dtd-version 6)
(t)
(nil)
"s1"
"s2"
"s1"
"p"
nil
�nil
�nil
�(nil)
(nil)
nil
1.1 xml-site/sources/xerces-p/samples.xml
Index: samples.xml
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
<s1 title="Sample Code">
<s2 title="Sample Code">
<p> Xerces.pm comes with three sample applications:</p>
<ul>
<li> <link idref="domprint">DOMPrint.pl</link>: Uses the DOM
serialize API to output a pretty-printed version of an XML file
to STDOUT.</li>
<li> <link idref="domcount">DOMCount.pl</link>: Uses the DOM
interface to output a count of the number of elements in an XML
document. </li>
<li> <link idref="domcreate">DOMCreate.pl</link>: Creates a simple XML
document using the DOM interface and writes it to STDOUT using
the DOM Tree serialize API.</li>
</ul>
</s2>
</s1>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]