GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
XML::Parser::Style::Elemental(3) User Contributed Perl Documentation XML::Parser::Style::Elemental(3)

XML::Parser::Style::Elemental - a slightly more advanced and flexible object tree style for XML::Parser

 #!/usr/bin/perl -w
 use XML::Parser;
 use Data::Dumper;
 my $p = XML::Parser->new( Style => 'Elemental', Pkg => 'E' );
 my $doc = <<DOC;
 <foo>
     <bar key="value">The world is foo enough.</bar>
 </foo>
 DOC
 my ($e) = $p->parse($doc);
 print Data::Dumper->Dump( [$e] );
 
 my $test_node = $e->contents->[0];
 print "root: ".$test_node->root." is ".$e."\n";
 print "text content of ".$test_node->name."\n";
 print $test_node->text_content;

This module is similar to the XML::Parser Objects style, but slightly more advanced and flexible. Like the Objects style, an object is created for each element. Elemental uses a dynamic class factory to create objects with accessor methods or can use any supplied classes that support the same method signatures. This module also provides full namespace support when the "Namespace" option is in use in addition to a "No_Whitespace" option for stripping out extraneous non-markup characters that are commonly introduced when formatting XML to be human readable.

Elemental style creates its parse tree with three class types -- Document, Element and Character. Developers have the option of using the built-in dynamic classes or registering their own. The following explains the purpose and method prototypes of each class type.

Elemental specific options are set in the XML::Parser constructor through a hash element with a key of 'Elemental', The value of Elemental is expected to be a hash reference with one of more of the option keys detailed in the following sections.

When parsing a document, Elemental uses a dynamic class factory to create minimal lightweight objects with accessor methods. These classes implement the pattern detailed in "CLASS TYPES" in addition to a parameterless constructor method of "new". Similar to the Objects style these classes are blessed into the package set with the "Pkg" option.

Here we create a parser that uses Elemental to create Document, Element and Characters objects in the E package.

 my $p = XML::Parser->new( Style => 'Elemental', Pkg => 'E' );

If you require something more functional then the generated dynamic classes you can register your own with Elemental. Like the Elemental class types, the option keys are "Document", "Element" and "Characters". Here we register three classes and turn on the "No_Whitespace" option.

 my $p = XML::Parser->new(  Style => 'Elemental',
                            Namespace => 1,
                            Elemental=>{
                                    Document=>'Foo::Doc',
                                    Element=>'Foo::El',
                                    Characters=>'Foo::Chars',
                                    No_Whitespace=>1
                            }
                         );

Note that, the same class can be registered for more then one class type as long as it supports all of the necessary method prototypes it is being registered to handle. See "CLASS TYPES" for more detail.

When set to true, "No_Whitespace" causes Elemental to pass over character strings of all whitespace instead of creating a new Character object. This options is helpful in stripping out extraneous non-markup characters that are commonly introduced when formatting XML to be human readable.

XML::Parser::Style::Objects

Implement xml::base support instead of No_Whitespace.

The software is released under the Artistic License. The terms of the Artistic License are described at <http://www.perl.com/language/misc/Artistic.html>.

Except where otherwise noted, XML::Parser::Style::Elemental is Copyright 2004, Timothy Appnel, cpan@timaoutloud.org. All rights reserved.

Hey! The above document had some coding errors, which are explained below:

=begin without a target?
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
'=end' without a target?
2004-04-18 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.