You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by ted sandler <te...@rcn.com> on 2002/03/16 10:42:40 UTC

problems creating treewalkers in Xerces-perl-1.5.2

Hi.  The XML tools that you guys at Apache have been building are fantastic
and I want to let you know how helpful it's been to my work.

I am emailing because I am having difficulty creating a tree walker for a
parsed documents and I think it's due to a deficiency in the perl API to
Xerces-C.  The problem centers around the fact that there is no way to
create a new XML::Xerces::DOM_NodeFilter object (I've included the relevent
portion of the Xerces.pm module at the bottom of this email).  The new()
method is entirely absent.

Consequently, there seems no way to create a treewalker object because
DOM_Document_createTreeWalker( ) requires a DOM_NodeFiler object as its 3
argument.  Is there any way to get around this?

Thanks for any and all help,

Sincerely,
ted sandler


############# Class : XML::Xerces::DOM_NodeFilter ##############

package XML::Xerces::DOM_NodeFilter;
@ISA = qw( XML::Xerces );
%OWNER = ();
%ITERATORS = ();
*FILTER_ACCEPT = *XML::Xercesc::DOM_NodeFilter_FILTER_ACCEPT;
*FILTER_REJECT = *XML::Xercesc::DOM_NodeFilter_FILTER_REJECT;
*FILTER_SKIP = *XML::Xercesc::DOM_NodeFilter_FILTER_SKIP;
*SHOW_ALL = *XML::Xercesc::DOM_NodeFilter_SHOW_ALL;
*SHOW_ELEMENT = *XML::Xercesc::DOM_NodeFilter_SHOW_ELEMENT;
*SHOW_ATTRIBUTE = *XML::Xercesc::DOM_NodeFilter_SHOW_ATTRIBUTE;
*SHOW_TEXT = *XML::Xercesc::DOM_NodeFilter_SHOW_TEXT;
*SHOW_CDATA_SECTION = *XML::Xercesc::DOM_NodeFilter_SHOW_CDATA_SECTION;
*SHOW_ENTITY_REFERENCE =
*XML::Xercesc::DOM_NodeFilter_SHOW_ENTITY_REFERENCE;
*SHOW_ENTITY = *XML::Xercesc::DOM_NodeFilter_SHOW_ENTITY;
*SHOW_PROCESSING_INSTRUCTION =
*XML::Xercesc::DOM_NodeFilter_SHOW_PROCESSING_INSTRUCTION;
*SHOW_COMMENT = *XML::Xercesc::DOM_NodeFilter_SHOW_COMMENT;
*SHOW_DOCUMENT = *XML::Xercesc::DOM_NodeFilter_SHOW_DOCUMENT;
*SHOW_DOCUMENT_TYPE = *XML::Xercesc::DOM_NodeFilter_SHOW_DOCUMENT_TYPE;
*SHOW_DOCUMENT_FRAGMENT =
*XML::Xercesc::DOM_NodeFilter_SHOW_DOCUMENT_FRAGMENT;
*SHOW_NOTATION = *XML::Xercesc::DOM_NodeFilter_SHOW_NOTATION;

*acceptNode = *XML::Xercesc::DOM_NodeFilter_acceptNode;
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

    my $parser = XML::Xerces::DOMParser->new();
    $parser->setValidationScheme ($validate);
    $parser->setDoNamespaces ($namespace);
    $parser->setCreateEntityReferenceNodes(1);
    $parser->setDoSchema ($schema);

    my $error_handler = XML::Xerces::PerlErrorHandler->new();
    $parser->setErrorHandler($error_handler);

    eval { $parser->parse(XML::Xerces::LocalFileInputSource->new($file)); };

    die($@) if $@;

    my $doc = $parser->getDocument();
    my $tw = $doc->createTreeWalker();  # <-- This doesn't work!




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Fredrick Paul Eisele" <ph...@netarx.com> writes:

> We use xerces-p every (week)day.
> Have you had any luck getting it on CPAN?

I can put it on CPAN whenever I'd like. I'm a registered author
already. I still haven't gotten namespace confirmation, but that isn't
necessary for me to upload it.

What I've been waiting for is, an official release of XML-Xerces-1.6.0
to upload. Since I haven't made any time to do that, I don't have
anything to upload.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by Fredrick Paul Eisele <ph...@netarx.com>.
We use xerces-p every (week)day.
Have you had any luck getting it on CPAN?



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Steven N. Hirsch" <hi...@btv.ibm.com> writes:

> On 16 Mar 2002, Jason E. Stewart wrote:
> 
> > You're welcome. Thanks for letting us know. I do a lot of work for
> > this project, and it's completely voluntary. I haven't had a lot of
> > time to devote to the project lately, and I've felt a bit guilty. 
> > 
> > But at the same time, I haven't heard a lot of feedback recently, and
> > so I begin to wonder whether I'm developing an XML parser just for
> > myself. 
> 
> Not at all!  I've been quite happy with Xerces-perl and haven't had a 
> compelling reason to post anything in a while.  

Good! Glad to hear it.

It's funny but it seems that the only way a maintainer can know how
popular a project is is by how many people complain about something
not working. Not exactly optimal feedback - it encourages me to make a
'broken' release every now and then just to see who notices ;-)

> That said, I am curious about your recommendations for handling
> 'xlink' constructs.  In my naivety, I thought that the parser would
> either resolve these and include them or have a switch to effect
> that behavior.  Since that turns out not to be the case, I'd
> appreciate some input on how to accomplish this through the IDOM
> interface, i.e. have the parsed model available with the xlinked
> element replaced by the target document.

That's a big project. What I would do is to not touch the core IDOM,
but to parse the document as-is, then pass the IDOM_Document instance
off to a custom library method that you write to handle XLink'ed
nodes. It would traverse the tree, and replace the XLink nodes with
the ones being referered to.

To me it's simpler to do it in Perl. Otherwise, you'll have to
implement it in C++, and create some subclass of IDOMParser, like
IDOMParser-XLink, that does it for you automatically.

> I keep bashing away at the AIX exception-handling issues as time
> permits, but have gotten exactly nowhere with it :-(.  It's tough to
> debug something when the debugger either dumps core itself or
> refuses to load the executable.

Hmmm. I wish I had some valuable information, but I don't.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by "Steven N. Hirsch" <hi...@btv.ibm.com>.
On 16 Mar 2002, Jason E. Stewart wrote:

> You're welcome. Thanks for letting us know. I do a lot of work for
> this project, and it's completely voluntary. I haven't had a lot of
> time to devote to the project lately, and I've felt a bit guilty. 
> 
> But at the same time, I haven't heard a lot of feedback recently, and
> so I begin to wonder whether I'm developing an XML parser just for
> myself. 

Not at all!  I've been quite happy with Xerces-perl and haven't had a 
compelling reason to post anything in a while.  That said, I am curious 
about your recommendations for handling 'xlink' constructs.  In my 
naivety, I thought that the parser would either resolve these and include 
them or have a switch to effect that behavior.  Since that turns out not 
to be the case, I'd appreciate some input on how to accomplish this 
through the IDOM interface, i.e. have the parsed model available with 
the xlinked element replaced by the target document.

I keep bashing away at the AIX exception-handling issues as time permits, 
but have gotten exactly nowhere with it :-(.  It's tough to debug 
something when the debugger either dumps core itself or refuses to load 
the executable.

Steve

-- 
----------------------------------------------------------------
Steven N. Hirsch       tie-line: 446-6557     ext: 802-769-6557

Staff Engineer                     Methodology Integration Team
ASIC Product Development           IBM Microelectronics
----------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"ted sandler" <te...@rcn.com> writes:

> Hi.  The XML tools that you guys at Apache have been building are
> fantastic and I want to let you know how helpful it's been to my
> work.

Hey Ted,

You're welcome. Thanks for letting us know. I do a lot of work for
this project, and it's completely voluntary. I haven't had a lot of
time to devote to the project lately, and I've felt a bit guilty. 

But at the same time, I haven't heard a lot of feedback recently, and
so I begin to wonder whether I'm developing an XML parser just for
myself. 

Feedback like yours, gives me a reason to prioritize the XML::Xerces
work. 

> I am emailing because I am having difficulty creating a tree walker for a
> parsed documents and I think it's due to a deficiency in the perl API to
> Xerces-C.  The problem centers around the fact that there is no way to
> create a new XML::Xerces::DOM_NodeFilter object (I've included the relevent
> portion of the Xerces.pm module at the bottom of this email).  The new()
> method is entirely absent.
> 
> Consequently, there seems no way to create a treewalker object because
> DOM_Document_createTreeWalker( ) requires a DOM_NodeFiler object as its 3
> argument.  Is there any way to get around this?

This is because I've never built one, and so I never checked that this
API actually works. 

>From the example code that I found in the xerces-c archive at:

  http://marc.theaimsgroup.com/?l=xerces-c-dev&w=2&r=1&s=DOM_NodeFilter&q=b

It seems that DOM_NodeFilter is really just an interface, and you are
supposed to create your own class that implements that interface.

There is a problem there. The issue is that whatever class you create,
call it MyNodeFilter, is going to have to provide some object that can
be passed to Xerces-C and be stored for callbacks, because that is how
the acceptFilter() method works, I think. Whenever the treewalker hits
a node, it calls acceptFilter() on the MyNodeFilter instance you gave
it. 

So what is the problem? The problem is that Xerces-C can only store
pointers to C++ objects. That means that currently you can't have a
Perl only class that does what you want. 

That sucks.

I've hit this problem many times before - there are many interfaces
that exist in Xerces-C like all the *Handler classes: ErrorHandler,
ContentHandler, etc. Each time I implemented a Separate solution for
them: a C++ callback class that simply stored the pointer to a Perl
object (the MyNodeFilter instance in your case) and forwarded all
method calls to it. That way, whenever you create a treewalker and
pass in an instance of your MyNodeFilter class, I would have to first
create an instance of the C++ callback class, passing it the
MyNodeFilter instance you provided, and then sending the C++ callback
class instance to the Xerces-C treewalker creation code.

As you can see it's a bit complicated, and since it's code that has to
go in Xerces.pm it's not something that a user is expected to be able
to do. I tell you not because I expect you to roll up your sleeves and
begin hacking Xerces.pm, but just to let you know it's possible.

I'll take a look at it, and make another experimental release of 1.6.0
with that functionality. That means that you'll have to get
Xerces-C-1.6.0 in order to get it to work.

Cheers,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: problems creating treewalkers in Xerces-perl-1.5.2

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"ted sandler" <te...@rcn.com> writes:

> I am emailing because I am having difficulty creating a tree walker
> for a parsed documents and I think it's due to a deficiency in the
> perl API to Xerces-C.  

Hey Ted,

I've just checked the fix for this into CVS. If you can, check out the
latest and take a look at t/DOM_TreeWalker.t or  t/DOM_NodeIterator.t
to see how to use DOM_NodeFilter's.

If you can't check out the code for CVS, let me know and I'll cut a
new release.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org