ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
RE: A Serializer within a Filter
by Calbazana, Al other posts by this author
Jul 9 2002 7:19PM messages near this date
view in the new Beta List Site
Re: Trouble installing XML::Filter::XSLT | RE: Perl and Sax parsing?
Ahhh...  It dawned on me to check the version number and low and behold it
was a later version of XML::SAX::Base.

Thanks!

Al

-----Original Message-----
From: Kip Hampton [mailto:khampton@[...].com] 
Sent: Wednesday, July 03, 2002 5:17 PM
To: Calbazana, Al; 'perl-xml@listserv.ActiveState.com'
Subject: Re: A Serializer within a Filter

At 04:05 PM 07/03/2002 -0400, Calbazana, Al wrote:

> Hello,
> 
> 
> 
> I am working on an application that filters a set of XML docs and, while 
> filtering, needs to break out of the parsing to create instances of 
> objects representing stateful data when I hit certain tags.  As the 
> document is parsed, I need to serialize these objects to XML and place 
> them in the event stream along with the document that I am parsing.  I am 
> using Sax filtering to accomplish the document parsing, tag recognition, 
> etc...  I am considering having an object perform the task of serializing 
> my stateful objects by generating Sax events, but I am not sure how to get 
> these events to the final "document handler" which will pull everything 
> together in one, nice, neat XML doc.
> 
> 
> 
> I took a look at Kip's article on "Writing SAX Drivers for Non-XML Data" 
> and this is exactly what I want to do.  The only difference is that I want 
> to generate events from within a filter and use my current filter's 
> Handler as the target for my events.  As far as I know, I can not get the 
> XML representation of my object and squeeze it into the a 
> start_element($el) call for example.  I would have to pass serialization 
> through the event stream along with everything else.  Correct?

Correct, you need to unwind your objects into the appropriate events in 
much the same way that a DOM Walker (like XML::LibXML::SAX::Generator) 
serializes a whole tree into a SAX event stream.

If your Filter inherits from XML::SAX::Base, you can get at the Filter's 
current Handler by doing $self-> get_handler() (or 
$self-> get_content_handler, etc...).

If the data structure of your objects are close to the structure of the XML 
representation, you might get a head start with XML::Generator::PerlData:

# inside one of the Filter's handler subs...

my $handler = $self-> get_handler;
my $driver  = XML::Generator::PerlData-> new( Handler => $handler );
$driver-> parse_chunk( $my_object );

HTH,
-kip

Kip Hampton
Perl and XML: http://xml.com/pub/q/perlxml
AxKit: http://axkit.org/

Join Us In San Diego!
http://conferences.oreillynet.com/os2002/
http://conferences.oreillynet.com/cs/os2002/view/e_sess/2533


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved