You can subscribe to this list here.
2002 |
Jan
(8) |
Feb
(22) |
Mar
(3) |
Apr
(13) |
May
(1) |
Jun
(4) |
Jul
|
Aug
(5) |
Sep
(9) |
Oct
(36) |
Nov
(7) |
Dec
(15) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(4) |
Feb
(1) |
Mar
(55) |
Apr
(25) |
May
(25) |
Jun
(4) |
Jul
(2) |
Aug
|
Sep
(12) |
Oct
(6) |
Nov
(14) |
Dec
(1) |
2004 |
Jan
(1) |
Feb
(8) |
Mar
(6) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(3) |
Nov
(11) |
Dec
|
2005 |
Jan
(14) |
Feb
(3) |
Mar
(4) |
Apr
(14) |
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(2) |
Nov
(2) |
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(19) |
Nov
(5) |
Dec
|
2007 |
Jan
(5) |
Feb
(1) |
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
(8) |
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Ilya M. <m_...@us...> - 2003-03-29 15:45:51
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t In directory sc8-pr-cvs1:/tmp/cvs-serv6810/t Modified Files: 02-functions.t Log Message: Test ok($xc->findvalue('foo:copy(3.14)') == 3.14); can fail because of precision errors in float math. Replace it with more robust test Index: 02-functions.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/02-functions.t,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- 02-functions.t 26 Mar 2003 15:26:46 -0000 1.6 +++ 02-functions.t 29 Mar 2003 15:45:48 -0000 1.7 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 27 }; +BEGIN { plan tests => 28 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -19,7 +19,8 @@ # copy string, real, integer, nodelist ok($xc->findvalue('foo:copy("bar")') eq 'bar'); -ok($xc->findvalue('foo:copy(3.14)') == 3.14); +ok($xc->findvalue('foo:copy(3.14)') < 3.141); # can't use == here because of +ok($xc->findvalue('foo:copy(3.14)') > 3.139); # float math ok($xc->findvalue('foo:copy(7)') == 7); ok($xc->find('foo:copy(//*)')->size() == 3); my ($foo)=$xc->findnodes('(//*)[2]'); |
From: Ilya M. <m_...@us...> - 2003-03-29 15:44:00
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv5708 Modified Files: XPathContext.xs Log Message: Add missing include for xpathInternals.h which fixes problems with float numbers used in xpath expressions on platforms where PV != double Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- XPathContext.xs 27 Mar 2003 10:06:37 -0000 1.25 +++ XPathContext.xs 29 Mar 2003 15:43:54 -0000 1.26 @@ -17,6 +17,7 @@ #include "perl-libxml-mm.h" #include "xpath.h" +#include "xpathInternals.h" #ifdef __cplusplus } @@ -128,7 +129,6 @@ AV * array_result; xmlXPathObjectPtr ret; - /* warn("result is a node list\n"); */ ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet((xmlNodePtr) NULL); array_result = (AV*)SvRV(perl_result); length = av_len(array_result); @@ -154,7 +154,6 @@ xmlNodePtr tmp_node; xmlXPathObjectPtr ret; - /* warn("result is a node\n"); */ ret = (xmlXPathObjectPtr)xmlXPathNewNodeSet(NULL); tmp_node = (xmlNodePtr)PmmSvNode(perl_result); xmlXPathNodeSetAdd(ret->nodesetval,tmp_node); @@ -166,12 +165,10 @@ return ret; } else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { - /* warn("result is a boolean\n"); */ return (xmlXPathObjectPtr) xmlXPathNewBoolean(SvIV(SvRV(perl_result))); } else if (sv_isa(perl_result, "XML::LibXML::Literal")) { - /* warn("result is a literal\n"); */ return (xmlXPathObjectPtr) xmlXPathNewCString(SvPV_nolen(SvRV(perl_result))); } @@ -180,10 +177,8 @@ xmlXPathNewFloat(SvNV(SvRV(perl_result))); } } else if (SvNOK(perl_result) || SvIOK(perl_result)) { - /* warn("result is an unblessed number\n"); */ return (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); } else { - /* warn("result is an unblessed string\n"); */ return (xmlXPathObjectPtr) xmlXPathNewCString(SvPV_nolen(perl_result)); } |
From: Ilya M. <m_...@us...> - 2003-03-27 10:06:40
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv31485 Modified Files: XPathContext.xs Log Message: Added 'PROTOTYPES: DISABLE' to shut up 'Please specify prototyping behavior for XPathContext.xs' warning Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- XPathContext.xs 26 Mar 2003 21:21:41 -0000 1.24 +++ XPathContext.xs 27 Mar 2003 10:06:37 -0000 1.25 @@ -431,6 +431,8 @@ MODULE = XML::LibXML::XPathContext PACKAGE = XML::LibXML::XPathContext +PROTOTYPES: DISABLE + SV* new( CLASS, pnode ) const char * CLASS |
From: Ilya M. <m_...@us...> - 2003-03-26 21:25:20
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv28268 Modified Files: MANIFEST Log Message: Updated Index: MANIFEST =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/MANIFEST,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- MANIFEST 14 Mar 2003 16:24:49 -0000 1.3 +++ MANIFEST 26 Mar 2003 21:25:12 -0000 1.4 @@ -1,3 +1,4 @@ +Changes LICENSE MANIFEST Makefile.PL |
From: Ilya M. <m_...@us...> - 2003-03-26 21:24:32
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv27879 Modified Files: README Log Message: Updated Index: README =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- README 14 Mar 2003 14:32:04 -0000 1.1.1.1 +++ README 26 Mar 2003 21:24:26 -0000 1.2 @@ -7,19 +7,90 @@ my $xc = XML::LibXML::XPathContext->new($node); $xc->registerNs($prefix, $namespace_uri); + $xc->registerFunction($name, sub { ... }); + $xc->registerFunctionNS($name, $namespace_uri, sub { ... }); + $xc->registerVarLookupFunc(sub { ... }, $data); + + $xc->unregisterNs($prefix); + $xc->unregisterFunction($name); + $xc->unregisterFunctionNS($name, $namespace_uri); + $xc->unregisterVarLookupFunc($name); my @nodes = $xc->findnodes($xpath); my $nodelist = $xc->findnodes($xpath); my $result = $xc->find($xpath); my $value = $xc->findvalue($xpath); + my $node = $xc->getContextNode; + $xc->setContextNode($node); + DESCRIPTION This module augments XML::LibXML by providing Perl interface to libxml2's xmlXPathContext structure. Besides just performing xpath statements on XML::LibXML's node trees it allows redefining certaint - aspects of xpath engine. + aspects of XPath engine. This modules allows - Methods + 1 registering namespace prefixes, + + 2 defining XPath functions in Perl, + + 3 defining variable lookup functions in Perl. + +EXAMPLES + Find all paragraph nodes in XHTML document + This example demonstrates *registerNs()* usage: + + my $xc = XML::LibXML::XPathContext->new($xhtml_doc); + $xc->registerNs('xhtml', 'http://www.w3.org/1999/xhtml'); + my @nodes = $xc->findnodes('//xhtml:p'); + + Find all nodes whose names match a Perl regular expression + This example demonstrates *registerFunction()* usage: + + my $perlmatch = sub { + die "Not a nodelist" + unless $_[0]->isa('XML::LibXML::NodeList'); + die "Missing a regular expression" + unless defined $_[1]; + + my $nodelist = XML::LibXML::NodeList->new; + my $i = 0; + while(my $node = $_[0]->get_node($i)) { + $nodelist->push($node) if $node->nodeName =~ $_[1]; + $i ++; + } + + return $nodelist; + }; + + my $xc = XML::LibXML::XPathContext->new($node); + $xc->registerFunction('perlmatch', $perlmatch); + my @nodes = $xc->findnodes('perlmatch(//*, "foo|bar")'); + + Use XPath variables to recycle results of previous evaluations + This example demonstrates *registerVarLookup()* usage: + + sub var_lookup { + my ($varname,$ns,$data)=@_; + return $data->{$varname}; + } + + my $areas = XML::LibXML->new->parse_file('areas.xml'); + my $empl = XML::LibXML->new->parse_file('employees.xml'); + + my $xc = XML::LibXML::XPathContext->new($empl); + + my %results = + ( + A => $xc->find('/employees/employee[@salary>10000]'), + B => $areas->find('/areas/area[district='Brooklyn']/street'), + ); + + # get names of employees from $A woring in an area listed in $B + $xc->registerVarLookupFunc(\&var_lookup,\%results); + my @nodes = $xc->findnodes('$A[work_area/street = $B]/name'); + +METHODS new($node) Creates a new XML::LibXML::XPathContext object with current node set to *$node*. @@ -27,6 +98,50 @@ registerNs($prefix, $namespace_uri) Registers namespace *$prefix* to *$namespace_uri*. + unregisterNs($prefix) + Unregisters namespace *$prefix*. + + registerVarLookupFunc($callback, $data) + Registers variable lookup function *$prefix*. The registered + function is executed by the XPath engine each time an XPath variable + is evaluated. It takes three arguments: *$data*, variable name, and + variable ns-URI and must return one value: a number or string or any + XML::LibXML object that can be a result of findnodes: Boolean, + Literal, Number, Node (e.g. Document, Element, etc.), or NodeList. + For convenience, simple (non-blessed) array references containing + only XML::LibXML::Node objects can be used instead of a + XML::LibXML::NodeList. + + getVarLookupData() + Returns the data that have been associated with a variable lookup + function during a previous call to *registerVarLookupFunc*. + + unregisterVarLookupFunc() + Unregisters variable lookup function and the associated lookup data. + + registerFunctionNS($name, $uri, $callback) + Registers an extension function *$name* in *$uri* namespace. + *$callback* must be a CODE reference. The arguments of the callback + function are either simple scalars or XML::LibXML::NodeList objects + depending on the XPath argument types. The function is responsible + for checking the argument number and types. Result of the callback + code must be a single value of the following types: a simple scalar + (number,string) or an arbitrary XML::LibXML object that can be a + result of findnodes: Boolean, Literal, Number, Node (e.g. Document, + Element, etc.), or NodeList. For convenience, simple (non-blessed) + array references containing only XML::LibXML::Node objects can be + used instead of a XML::LibXML::NodeList. + + unregisterFunctionNS($name, $uri) + Unregisters extension function *$name* in *$uri* namespace. Has the + same effect as passing "undef" as *$callback* to registerFunctionNS. + + registerFunction($name, $callback) + Same as *registerFunctionNS* but without a namespace. + + unregisterFunction($name) + Same as *unregisterFunctionNS* but without a namespace. + findnodes($xpath) Performs the xpath statement on the current node and returns the result as an array. In scalar context returns a @@ -52,14 +167,31 @@ certain shortcuts. This could be used as the equivalent of <xsl:value-of select="some_xpath"/>. + getContextNode() + Get the current context node. + + setContextNode($node) + Set the current context node. + +BUGS AND CAVEATS + XML::LibXML::XPathContext objects are not reentrant. It means you cannot + register a Perl function with a XML::LibXML::XPathContext object if this + Perl function uses itself the same XML::LibXML::XPathContext object + internally. + + For example, the following code will not work: + + my $xc = XML::LibXML::XPathContext->new($node); + $xc->registerFunction('func', sub { $xc->findvalue('1') }); + my $result = $xc->findvalue('func()'); + AUTHORS - Based on XML::LibXML code by Matt Sergeant and Christian Glahn. + Based on XML::LibXML and XML::XSLT code by Matt Sergeant and Christian + Glahn. Maintained by Ilya Martynov and Petr Pajas. - Copyright 2001-2002 AxKit.com Ltd, All rights reserved. - - Copyright 2003 Ilya Martynov, All rights reserved. + Copyright 2001-2003 AxKit.com Ltd, All rights reserved. SUPPORT For suggestions, bugreports etc. you may contact the maintainers @@ -69,5 +201,5 @@ the perl XML mailing list (per...@li...). SEE ALSO - XML::LibXML + XML::LibXML, XML::XSLT |
From: Ilya M. <m_...@us...> - 2003-03-26 21:21:45
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv26744 Modified Files: XPathContext.xs XPathContext.pm Log Message: Add unregisterNs() method Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- XPathContext.xs 26 Mar 2003 15:26:47 -0000 1.23 +++ XPathContext.xs 26 Mar 2003 21:21:41 -0000 1.24 @@ -531,8 +531,8 @@ void registerNs( pxpath_context, prefix, ns_uri ) SV * pxpath_context - char * prefix - char * ns_uri + SV * prefix + SV * ns_uri PREINIT: xmlXPathContextPtr ctxt = NULL; int ret = -1; @@ -543,9 +543,15 @@ } LibXML_configure_xpathcontext(ctxt); PPCODE: - ret = xmlXPathRegisterNs(ctxt, prefix, ns_uri); - if(ret == -1) { - croak("XPathContext:cannot register namespace"); + if(SvOK(ns_uri)) { + if(xmlXPathRegisterNs(ctxt, SvPV_nolen(prefix), + SvPV_nolen(ns_uri)) == -1) { + croak("XPathContext: cannot register namespace"); + } + } else { + if(xmlXPathRegisterNs(ctxt, SvPV_nolen(prefix), NULL) == -1) { + croak("XPathContext: cannot unregister namespace"); + } } SV* Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- XPathContext.pm 26 Mar 2003 17:16:46 -0000 1.15 +++ XPathContext.pm 26 Mar 2003 21:21:41 -0000 1.16 @@ -64,6 +64,12 @@ return; } +sub unregisterNs { + my ($self, $prefix) = @_; + $self->registerNs($prefix, undef); + return; +} + sub unregisterFunction { my ($self, $name) = @_; $self->registerFunctionNS($name, undef, undef); @@ -132,6 +138,7 @@ $xc->registerFunctionNS($name, $namespace_uri, sub { ... }); $xc->registerVarLookupFunc(sub { ... }, $data); + $xc->unregisterNs($prefix); $xc->unregisterFunction($name); $xc->unregisterFunctionNS($name, $namespace_uri); $xc->unregisterVarLookupFunc($name); @@ -238,6 +245,10 @@ =item B<registerNs($prefix, $namespace_uri)> Registers namespace I<$prefix> to I<$namespace_uri>. + +=item B<unregisterNs($prefix)> + +Unregisters namespace I<$prefix>. =item B<registerVarLookupFunc($callback, $data)> |
From: Ilya M. <m_...@us...> - 2003-03-26 21:21:43
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t In directory sc8-pr-cvs1:/tmp/cvs-serv26744/t Modified Files: 00-xpathcontext.t Log Message: Add unregisterNs() method Index: 00-xpathcontext.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/00-xpathcontext.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- 00-xpathcontext.t 20 Mar 2003 10:16:25 -0000 1.3 +++ 00-xpathcontext.t 26 Mar 2003 21:21:40 -0000 1.4 @@ -1,5 +1,5 @@ use Test; -BEGIN { plan tests => 16 }; +BEGIN { plan tests => 17 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -38,6 +38,11 @@ my $xc = XML::LibXML::XPathContext->new($doc1); $xc->registerNs('xxx', 'http://example.com/foobar'); ok($xc->findnodes('/xxx:foo')->pop->nodeName eq 'foo'); + +# test unregisterNs() +$xc->unregisterNs('xxx'); +eval { $xc->findnodes('/xxx:foo') }; +ok($@); # test getContextNode and setContextNode ok($xc->getContextNode->isSameNode($doc1)); |
From: Ilya M. <m_...@us...> - 2003-03-26 21:20:51
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv26350 Added Files: Changes Log Message: Added --- NEW FILE: Changes --- $Id: Changes,v 1.1 2003/03/26 21:20:45 m_ilya Exp $ Revision history for Perl module XML::LibXML::XPathContext. 0.01 Thu Mar 27 2003 * First version based on XML::LibXML and XML::XSLT code. |
From: Ilya M. <m_...@us...> - 2003-03-26 17:16:51
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv1575 Modified Files: XPathContext.pm Log Message: Cosmetic fixes Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- XPathContext.pm 26 Mar 2003 17:14:52 -0000 1.14 +++ XPathContext.pm 26 Mar 2003 17:16:46 -0000 1.15 @@ -38,9 +38,7 @@ sub findvalue { my ($self, $xpath) = @_; - my $res; - $res = $self->find($xpath); - return $res->to_literal->value; + return $self->find($xpath)->to_literal->value; } sub find { |
From: Ilya M. <m_...@us...> - 2003-03-26 17:14:58
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv690 Modified Files: XPathContext.pm Log Message: Make sure that indentation is consistently 4 spaces Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- XPathContext.pm 26 Mar 2003 16:22:16 -0000 1.13 +++ XPathContext.pm 26 Mar 2003 17:14:52 -0000 1.14 @@ -61,27 +61,27 @@ } sub registerFunction { - my ($self, $name, $sub)=@_; - $self->registerFunctionNS($name,undef,$sub); - return; + my ($self, $name, $sub) = @_; + $self->registerFunctionNS($name, undef, $sub); + return; } sub unregisterFunction { - my ($self, $name)=@_; - $self->registerFunctionNS($name,undef,undef); - return; + my ($self, $name) = @_; + $self->registerFunctionNS($name, undef, undef); + return; } sub unregisterFunctionNS { - my ($self, $name, $ns)=@_; - $self->registerFunctionNS($name,$ns,undef); - return; + my ($self, $name, $ns) = @_; + $self->registerFunctionNS($name, $ns, undef); + return; } sub unregisterVarLookupFunc { - my ($self)=@_; - $self->registerVarLookupFunc(undef,undef); - return; + my ($self) = @_; + $self->registerVarLookupFunc(undef, undef); + return; } # extension function perl dispatcher @@ -290,7 +290,6 @@ =item B<unregisterFunction($name)> Same as I<unregisterFunctionNS> but without a namespace. - =item B<findnodes($xpath)> |
From: Ilya M. <m_...@us...> - 2003-03-26 16:22:27
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv6005 Modified Files: XPathContext.pm Log Message: List unregister*** methods in SYNOPSIS Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- XPathContext.pm 26 Mar 2003 16:19:42 -0000 1.12 +++ XPathContext.pm 26 Mar 2003 16:22:16 -0000 1.13 @@ -134,6 +134,10 @@ $xc->registerFunctionNS($name, $namespace_uri, sub { ... }); $xc->registerVarLookupFunc(sub { ... }, $data); + $xc->unregisterFunction($name); + $xc->unregisterFunctionNS($name, $namespace_uri); + $xc->unregisterVarLookupFunc($name); + my @nodes = $xc->findnodes($xpath); my $nodelist = $xc->findnodes($xpath); my $result = $xc->find($xpath); |
From: Ilya M. <m_...@us...> - 2003-03-26 16:19:49
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv4701 Modified Files: XPathContext.pm Log Message: Fix links in POD Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- XPathContext.pm 26 Mar 2003 15:26:48 -0000 1.11 +++ XPathContext.pm 26 Mar 2003 16:19:42 -0000 1.12 @@ -144,10 +144,11 @@ =head1 DESCRIPTION -This module augments XML::LibXML by providing Perl interface to -libxml2's xmlXPathContext structure. Besides just performing xpath -statements on XML::LibXML's node trees it allows redefining certaint -aspects of XPath engine. This modules allows +This module augments L<XML::LibXML|XML::LibXML> by providing Perl +interface to libxml2's xmlXPathContext structure. Besides just +performing xpath statements on L<XML::LibXML|XML::LibXML>'s node trees +it allows redefining certaint aspects of XPath engine. This modules +allows =over 4 @@ -229,8 +230,8 @@ =item B<new($node)> -Creates a new XML::LibXML::XPathContext object with current node set -to I<$node>. +Creates a new XML::LibXML::XPathContext object with current node +set to I<$node>. =item B<registerNs($prefix, $namespace_uri)> @@ -242,11 +243,11 @@ is executed by the XPath engine each time an XPath variable is evaluated. It takes three arguments: I<$data>, variable name, and variable ns-URI and must return one value: a number or string or any -XML::LibXML object that can be a result of findnodes: Boolean, -Literal, Number, Node (e.g. Document, Element, etc.), or NodeList. -For convenience, simple (non-blessed) array references containing only -XML::LibXML::Node objects can be used instead of a -XML::LibXML::NodeList. +L<XML::LibXML|XML::LibXML> object that can be a result of findnodes: +Boolean, Literal, Number, Node (e.g. Document, Element, etc.), or +NodeList. For convenience, simple (non-blessed) array references +containing only L<XML::LibXML::Node|XML::LibXML::Node> objects can be +used instead of a L<XML::LibXML::NodeList|XML::LibXML::NodeList>. =item B<getVarLookupData()> @@ -261,17 +262,19 @@ Registers an extension function I<$name> in I<$uri> namespace. I<$callback> must be a CODE reference. The arguments of the -callback function are either simple scalars or XML::LibXML::NodeList -objects depending on the XPath argument types. The function is -responsible for checking the argument number and types. Result of the -callback code must be a single value of the following types: a simple -scalar (number,string) or an arbitrary XML::LibXML object that can be -a result of findnodes: Boolean, Literal, Number, Node (e.g. Document, -Element, etc.), or NodeList. For convenience, simple (non-blessed) -array references containing only XML::LibXML::Node objects can be used -instead of a XML::LibXML::NodeList. +callback function are either simple scalars or +L<XML::LibXML::NodeList|XML::LibXML::NodeList> objects depending on +the XPath argument types. The function is responsible for checking the +argument number and types. Result of the callback code must be a +single value of the following types: a simple scalar (number,string) +or an arbitrary L<XML::LibXML|XML::LibXML> object that can be a result +of findnodes: Boolean, Literal, Number, Node (e.g. Document, Element, +etc.), or NodeList. For convenience, simple (non-blessed) array +references containing only L<XML::LibXML::Node|XML::LibXML::Node> +objects can be used instead of a +L<XML::LibXML::NodeList|XML::LibXML::NodeList>. -=item B<registerFunctionNS($name, $uri)> +=item B<unregisterFunctionNS($name, $uri)> Unregisters extension function I<$name> in I<$uri> namespace. Has the same effect as passing C<undef> as I<$callback> to registerFunctionNS. @@ -289,17 +292,19 @@ Performs the xpath statement on the current node and returns the result as an array. In scalar context returns a -L<XML::LibXML::NodeList> object. +L<XML::LibXML::NodeList|XML::LibXML::NodeList> object. =item B<find($xpath)> Performs the xpath expression using the current node as the context of the expression, and returns the result depending on what type of result the XPath expression had. For example, the XPath C<1 * 3 + 52> -results in a L<XML::LibXML::Number> object being returned. Other -expressions might return a L<XML::LibXML::Boolean> object, or a -L<XML::LibXML::Literal> object (a string). Each of those objects uses -Perl's overload feature to "do the right thing" in different contexts. +results in a L<XML::LibXML::Number|XML::LibXML::Number> object being +returned. Other expressions might return a +L<XML::LibXML::Boolean|XML::LibXML::Boolean> object, or a +L<XML::LibXML::Literal|XML::LibXML::Literal> object (a string). Each +of those objects uses Perl's overload feature to "do the right thing" +in different contexts. =item B<findvalue($xpath)> @@ -324,10 +329,10 @@ =head1 BUGS AND CAVEATS -L<XML::LibXML::XPathContext> objects are not reentrant. It means you -cannot register a Perl function with a L<XML::LibXML::XPathContext> +XML::LibXML::XPathContext objects are not reentrant. It means you +cannot register a Perl function with a XML::LibXML::XPathContext object if this Perl function uses itself the same -L<XML::LibXML::XPathContext> object internally. +XML::LibXML::XPathContext object internally. For example, the following code will not work: @@ -337,8 +342,8 @@ =head1 AUTHORS -Based on L<XML::LibXML> and L<XML::XSLT> code by Matt Sergeant and -Christian Glahn. +Based on L<XML::LibXML|XML::LibXML> and L<XML::XSLT|XML::XSLT> code by +Matt Sergeant and Christian Glahn. Maintained by Ilya Martynov and Petr Pajas. @@ -354,6 +359,6 @@ =head1 SEE ALSO -L<XML::LibXML>, L<XML::XSLT> +L<XML::LibXML|XML::LibXML>, L<XML::XSLT|XML::XSLT> =cut |
From: Petr P. <pa...@us...> - 2003-03-26 15:26:53
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv10352 Modified Files: XPathContext.xs XPathContext.pm Log Message: - support for unregisering - extension functions can be registered by name - POD update Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- XPathContext.xs 25 Mar 2003 20:05:15 -0000 1.22 +++ XPathContext.xs 26 Mar 2003 15:26:47 -0000 1.23 @@ -287,8 +287,10 @@ strkey = SvPV(key, len); perl_function = hv_fetch((HV*)SvRV(data), strkey, len, 0); - if ( perl_function == NULL || !SvROK(*perl_function) || - SvTYPE(SvRV(*perl_function)) != SVt_PVCV ) { + if ( perl_function == NULL || !SvOK(*perl_function) || + !(SvPOK(*perl_function) || + (SvROK(*perl_function) && + SvTYPE(SvRV(*perl_function)) == SVt_PVCV))) { croak("XPathContext: lost perl extension function!"); } SvREFCNT_dec(key); @@ -590,14 +592,17 @@ croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); - if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) { - pfdr = newRV_inc((SV*) newAV()); - av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_func)); - av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_data)); - } else { - croak("XPathContext: 1st argument is not a CODE reference"); + if (SvOK(lookup_func)) { + if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) { + pfdr = newRV_inc((SV*) newAV()); + av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_func)); + av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_data)); + } else { + croak("XPathContext: 1st argument is not a CODE reference"); + } } if (ctxt->varLookupData != NULL) { + /* free previous lookup data */ if (SvTYPE(SvRV((SV *)ctxt->varLookupData)) == SVt_PVAV) { SvREFCNT_dec((SV *)ctxt->varLookupData); ctxt->varLookupData = NULL; @@ -607,10 +612,15 @@ } } PPCODE: - xmlXPathRegisterVariableLookup(ctxt, LibXML_generic_variable_lookup, pfdr); - if (ctxt->varLookupData==NULL || ctxt->varLookupData != pfdr) { - croak( "XPathContext: registration failure" ); - } + if (SvOK(lookup_func)) { + xmlXPathRegisterVariableLookup(ctxt, LibXML_generic_variable_lookup, pfdr); + if (ctxt->varLookupData==NULL || ctxt->varLookupData != pfdr) { + croak( "XPathContext: registration failure" ); + } + } else { + /* unregister */ + xmlXPathRegisterVariableLookup(ctxt, NULL, NULL); + } void registerFunctionNS( pxpath_context, name, uri, func) @@ -631,17 +641,25 @@ croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); - if ( SvTYPE(SvRV(func)) == SVt_PVCV ) { + if ( !SvOK(func) || SvOK(func) && + ((SvROK(func) && SvTYPE(SvRV(func)) == SVt_PVCV ) || SvPOK(func))) { if (ctxt->funcLookupData == NULL) { - pfdr = newRV_inc((SV*) newHV()); - ctxt->funcLookupData = pfdr; + if (SvOK(func)) { + pfdr = newRV_inc((SV*) newHV()); + ctxt->funcLookupData = pfdr; + } else { + /* looks like no perl function was never registered, */ + /* nothing to unregister */ + warn("XPathContext: nothing to unregister"); + return; + } } else { if (SvTYPE(SvRV((SV *)ctxt->funcLookupData)) == SVt_PVHV) { /* good, it's a HV */ pfdr = (SV *)ctxt->funcLookupData; } else { croak ("XPathContext: cannot register: funcLookupData structure occupied"); - } + } } key = newSVpvn("",0); if (SvOK(uri)) { @@ -652,18 +670,25 @@ sv_catpv(key, (const char*)name); strkey = SvPV(key, len); /* warn("Trying to store function '%s' in %d\n", strkey, pfdr); */ - hv_store((HV *)SvRV(pfdr),strkey, len, SvREFCNT_inc(func), 0); + if (SvOK(func)) { + hv_store((HV *)SvRV(pfdr),strkey, len, SvREFCNT_inc(func), 0); + } else { + /* unregister */ + hv_delete((HV *)SvRV(pfdr),strkey, len, G_DISCARD); + } SvREFCNT_dec(key); } else { - croak("XPathContext: 3rd argument is not a CODE reference"); + croak("XPathContext: 3rd argument is not a CODE reference or function name"); } PPCODE: if (SvOK(uri)) { - /* warn("Registering function with NS '%s' (uri: %s)\n", name, uri); */ - xmlXPathRegisterFuncNS(ctxt, name, SvPV(uri, len), LibXML_generic_extension_function); + xmlXPathRegisterFuncNS(ctxt, name, SvPV(uri, len), + (SvOK(func) ? + LibXML_generic_extension_function : NULL)); } else { - /* warn("Registering function '%s'\n", name); */ - xmlXPathRegisterFunc(ctxt, name, LibXML_generic_extension_function); + xmlXPathRegisterFunc(ctxt, name, + (SvOK(func) ? + LibXML_generic_extension_function : NULL)); } void Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- XPathContext.pm 26 Mar 2003 11:47:32 -0000 1.10 +++ XPathContext.pm 26 Mar 2003 15:26:48 -0000 1.11 @@ -66,6 +66,24 @@ return; } +sub unregisterFunction { + my ($self, $name)=@_; + $self->registerFunctionNS($name,undef,undef); + return; +} + +sub unregisterFunctionNS { + my ($self, $name, $ns)=@_; + $self->registerFunctionNS($name,$ns,undef); + return; +} + +sub unregisterVarLookupFunc { + my ($self)=@_; + $self->registerVarLookupFunc(undef,undef); + return; +} + # extension function perl dispatcher # borrowed from XML::LibXSLT @@ -114,7 +132,7 @@ $xc->registerNs($prefix, $namespace_uri); $xc->registerFunction($name, sub { ... }); $xc->registerFunctionNS($name, $namespace_uri, sub { ... }); - $xc->registerVariableLookup(sub { ... }, $data); + $xc->registerVarLookupFunc(sub { ... }, $data); my @nodes = $xc->findnodes($xpath); my $nodelist = $xc->findnodes($xpath); @@ -157,7 +175,7 @@ $xc->registerNs('xhtml', 'http://www.w3.org/1999/xhtml'); my @nodes = $xc->findnodes('//xhtml:p'); -=head2 Find all nodes which names match a Perl regular expression +=head2 Find all nodes whose names match a Perl regular expression This example demonstrates I<registerFunction()> usage: @@ -168,7 +186,6 @@ unless defined $_[1]; my $nodelist = XML::LibXML::NodeList->new; - my $i = 0; while(my $node = $_[0]->get_node($i)) { $nodelist->push($node) if $node->nodeName =~ $_[1]; @@ -182,6 +199,30 @@ $xc->registerFunction('perlmatch', $perlmatch); my @nodes = $xc->findnodes('perlmatch(//*, "foo|bar")'); +=head2 Use XPath variables to recycle results of previous evaluations + +This example demonstrates I<registerVarLookup()> usage: + + sub var_lookup { + my ($varname,$ns,$data)=@_; + return $data->{$varname}; + } + + my $areas = XML::LibXML->new->parse_file('areas.xml'); + my $empl = XML::LibXML->new->parse_file('employees.xml'); + + my $xc = XML::LibXML::XPathContext->new($empl); + + my %results = + ( + A => $xc->find('/employees/employee[@salary>10000]'), + B => $areas->find('/areas/area[district='Brooklyn']/street'), + ); + + # get names of employees from $A woring in an area listed in $B + $xc->registerVarLookupFunc(\&var_lookup,\%results); + my @nodes = $xc->findnodes('$A[work_area/street = $B]/name'); + =head1 METHODS =over 4 @@ -212,6 +253,10 @@ Returns the data that have been associated with a variable lookup function during a previous call to I<registerVarLookupFunc>. +=item B<unregisterVarLookupFunc()> + +Unregisters variable lookup function and the associated lookup data. + =item B<registerFunctionNS($name, $uri, $callback)> Registers an extension function I<$name> in I<$uri> @@ -226,9 +271,19 @@ array references containing only XML::LibXML::Node objects can be used instead of a XML::LibXML::NodeList. +=item B<registerFunctionNS($name, $uri)> + +Unregisters extension function I<$name> in I<$uri> namespace. Has the +same effect as passing C<undef> as I<$callback> to registerFunctionNS. + =item B<registerFunction($name, $callback)> Same as I<registerFunctionNS> but without a namespace. + +=item B<unregisterFunction($name)> + +Same as I<unregisterFunctionNS> but without a namespace. + =item B<findnodes($xpath)> |
From: Petr P. <pa...@us...> - 2003-03-26 15:26:52
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t In directory sc8-pr-cvs1:/tmp/cvs-serv10352/t Modified Files: 02-functions.t 01-variables.t Log Message: - support for unregisering - extension functions can be registered by name - POD update Index: 02-functions.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/02-functions.t,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- 02-functions.t 21 Mar 2003 20:11:02 -0000 1.5 +++ 02-functions.t 26 Mar 2003 15:26:46 -0000 1.6 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 23 }; +BEGIN { plan tests => 27 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -33,6 +33,22 @@ $xc->registerFunction('dummy', sub { 'DUMMY' }); ok($xc->findvalue('dummy()') eq 'DUMMY'); +# unregister it +$xc->unregisterFunction('dummy'); +eval { $xc->findvalue('dummy()') }; +ok ($@); + +# retister by name +sub dummy2 { 'DUMMY2' }; +$xc->registerFunction('dummy2', 'dummy2'); +ok($xc->findvalue('dummy2()') eq 'DUMMY2'); + +# unregister +$xc->unregisterFunction('dummy2'); +eval { $xc->findvalue('dummy2()') }; +ok ($@); + + # a mix of different arguments types $xc->registerFunction('join', sub { join shift, @@ -44,6 +60,11 @@ ok($xc->findvalue('join("","a","b","c")') eq 'abc'); ok($xc->findvalue('join("-","a",/foo,//*)') eq 'a-foo-foo-bar-bar'); ok($xc->findvalue('join("-",foo:copy(//*))') eq 'foo-bar-bar'); + +# unregister foo:copy +$xc->unregisterFunctionNS('copy','urn:foo'); +eval { $xc->findvalue('foo:copy("bar")') }; +ok ($@); # test context locking mechanism $xc->registerFunction('test-lock1', sub { $xc->find('1') }); Index: 01-variables.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/01-variables.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- 01-variables.t 14 Mar 2003 16:26:08 -0000 1.2 +++ 01-variables.t 26 Mar 2003 15:26:47 -0000 1.3 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 30 }; +BEGIN { plan tests => 31 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -46,7 +46,7 @@ my $xc = XML::LibXML::XPathContext->new($doc); ok(!defined($xc->getVarLookupData)); $xc->registerVarLookupFunc(\&get_variable,\%variables); -ok(defined($xc->getVarLookupData)); +ok(defined($xc->getVarLookupData)); my $h1=$xc->getVarLookupData; my $h2=\%variables; ok("$h1" eq "$h2" ); @@ -71,3 +71,8 @@ ok($xc->findnodes('$f')->pop->nodeName eq 'a'); ok($xc->findnodes('$f')->pop->isSameNode($variables{f})); ok($xc->findnodes('$g')->pop->isSameNode($variables{g})); + +# unregiser variable lookup +$xc->unregisterVarLookupFunc(); +eval { $xc->find('$a') }; +ok($@); |
From: Petr P. <pa...@us...> - 2003-03-26 11:47:37
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv2833 Modified Files: XPathContext.pm Log Message: - minor POD corrections Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- XPathContext.pm 25 Mar 2003 21:06:13 -0000 1.9 +++ XPathContext.pm 26 Mar 2003 11:47:32 -0000 1.10 @@ -203,11 +203,14 @@ variable ns-URI and must return one value: a number or string or any XML::LibXML object that can be a result of findnodes: Boolean, Literal, Number, Node (e.g. Document, Element, etc.), or NodeList. +For convenience, simple (non-blessed) array references containing only +XML::LibXML::Node objects can be used instead of a +XML::LibXML::NodeList. =item B<getVarLookupData()> -Returns the data associated with a variable lookup function during a -previous call to I<registerVarLookupFunc>. +Returns the data that have been associated with a variable lookup +function during a previous call to I<registerVarLookupFunc>. =item B<registerFunctionNS($name, $uri, $callback)> @@ -219,7 +222,9 @@ callback code must be a single value of the following types: a simple scalar (number,string) or an arbitrary XML::LibXML object that can be a result of findnodes: Boolean, Literal, Number, Node (e.g. Document, -Element, etc.), or NodeList. +Element, etc.), or NodeList. For convenience, simple (non-blessed) +array references containing only XML::LibXML::Node objects can be used +instead of a XML::LibXML::NodeList. =item B<registerFunction($name, $callback)> @@ -254,11 +259,11 @@ =item B<getContextNode()> -Get current context node. +Get the current context node. =item B<setContextNode($node)> -Set current context node. +Set the current context node. =back @@ -266,10 +271,10 @@ L<XML::LibXML::XPathContext> objects are not reentrant. It means you cannot register a Perl function with a L<XML::LibXML::XPathContext> -object if this Perl function uses itself same +object if this Perl function uses itself the same L<XML::LibXML::XPathContext> object internally. -For example following code will not work: +For example, the following code will not work: my $xc = XML::LibXML::XPathContext->new($node); $xc->registerFunction('func', sub { $xc->findvalue('1') }); |
From: Ilya M. <m_...@us...> - 2003-03-25 21:06:17
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv24486 Modified Files: XPathContext.pm Log Message: Added XML::XSLT in SEE ALSO section in POD Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- XPathContext.pm 25 Mar 2003 21:05:33 -0000 1.8 +++ XPathContext.pm 25 Mar 2003 21:06:13 -0000 1.9 @@ -294,6 +294,6 @@ =head1 SEE ALSO -L<XML::LibXML> +L<XML::LibXML>, L<XML::XSLT> =cut |
From: Ilya M. <m_...@us...> - 2003-03-25 21:05:41
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv24187 Modified Files: XPathContext.pm Log Message: Mention node locking and add examples to POD documentation Index: XPathContext.pm =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- XPathContext.pm 20 Mar 2003 14:51:45 -0000 1.7 +++ XPathContext.pm 25 Mar 2003 21:05:33 -0000 1.8 @@ -114,7 +114,7 @@ $xc->registerNs($prefix, $namespace_uri); $xc->registerFunction($name, sub { ... }); $xc->registerFunctionNS($name, $namespace_uri, sub { ... }); - $xc->registerVariableLookup(sub { ... },$data); + $xc->registerVariableLookup(sub { ... }, $data); my @nodes = $xc->findnodes($xpath); my $nodelist = $xc->findnodes($xpath); @@ -129,9 +129,60 @@ This module augments XML::LibXML by providing Perl interface to libxml2's xmlXPathContext structure. Besides just performing xpath statements on XML::LibXML's node trees it allows redefining certaint -aspects of xpath engine. +aspects of XPath engine. This modules allows -=head2 Methods +=over 4 + +=item 1 + +registering namespace prefixes, + +=item 2 + +defining XPath functions in Perl, + +=item 3 + +defining variable lookup functions in Perl. + +=back + +=head1 EXAMPLES + +=head2 Find all paragraph nodes in XHTML document + +This example demonstrates I<registerNs()> usage: + + my $xc = XML::LibXML::XPathContext->new($xhtml_doc); + $xc->registerNs('xhtml', 'http://www.w3.org/1999/xhtml'); + my @nodes = $xc->findnodes('//xhtml:p'); + +=head2 Find all nodes which names match a Perl regular expression + +This example demonstrates I<registerFunction()> usage: + + my $perlmatch = sub { + die "Not a nodelist" + unless $_[0]->isa('XML::LibXML::NodeList'); + die "Missing a regular expression" + unless defined $_[1]; + + my $nodelist = XML::LibXML::NodeList->new; + + my $i = 0; + while(my $node = $_[0]->get_node($i)) { + $nodelist->push($node) if $node->nodeName =~ $_[1]; + $i ++; + } + + return $nodelist; + }; + + my $xc = XML::LibXML::XPathContext->new($node); + $xc->registerFunction('perlmatch', $perlmatch); + my @nodes = $xc->findnodes('perlmatch(//*, "foo|bar")'); + +=head1 METHODS =over 4 @@ -211,15 +262,27 @@ =back +=head1 BUGS AND CAVEATS + +L<XML::LibXML::XPathContext> objects are not reentrant. It means you +cannot register a Perl function with a L<XML::LibXML::XPathContext> +object if this Perl function uses itself same +L<XML::LibXML::XPathContext> object internally. + +For example following code will not work: + + my $xc = XML::LibXML::XPathContext->new($node); + $xc->registerFunction('func', sub { $xc->findvalue('1') }); + my $result = $xc->findvalue('func()'); + =head1 AUTHORS -Based on L<XML::LibXML> code by Matt Sergeant and Christian Glahn. +Based on L<XML::LibXML> and L<XML::XSLT> code by Matt Sergeant and +Christian Glahn. Maintained by Ilya Martynov and Petr Pajas. -Copyright 2001-2002 AxKit.com Ltd, All rights reserved. - -Copyright 2003 Ilya Martynov, All rights reserved. +Copyright 2001-2003 AxKit.com Ltd, All rights reserved. =head1 SUPPORT |
From: Ilya M. <m_...@us...> - 2003-03-25 20:05:24
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv30172 Modified Files: XPathContext.xs Log Message: Use XPathContext: prefix in all croak messages Don't add \n at the end of croak messages so croak doesn't suppress file and line number info in error message. Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- XPathContext.xs 24 Mar 2003 09:26:48 -0000 1.21 +++ XPathContext.xs 25 Mar 2003 20:05:15 -0000 1.22 @@ -210,12 +210,12 @@ data = (SV *) varLookupData; if (varLookupData == NULL || !SvROK(data) || SvTYPE(SvRV(data)) != SVt_PVAV) { - croak("XPathContext: lost variable lookup data structure!\n"); + croak("XPathContext: lost variable lookup data structure!"); } lookup_func = av_fetch((AV *) SvRV(data),0,0 ); if ( lookup_func == NULL || !SvROK(*lookup_func) || SvTYPE(SvRV(*lookup_func)) != SVt_PVCV ) { - croak("XPathContext: lost variable lookup function!\n"); + croak("XPathContext: lost variable lookup function!"); } lookup_data = av_fetch((AV *) SvRV(data),1,0 ); @@ -233,9 +233,9 @@ SPAGAIN; if (SvTRUE(ERRSV)) { POPs; - croak("XPathContext: error coming back from variable lookup function. %s\n", SvPV_nolen(ERRSV)); + croak("XPathContext: error coming back from variable lookup function. %s", SvPV_nolen(ERRSV)); } - if (count != 1) croak("XPathContext: variable lookup function returned more than one argument!\n"); + if (count != 1) croak("XPathContext: variable lookup function returned more than one argument!"); ret = LibXML_perldata_to_LibXMLdata(NULL, POPs); @@ -271,7 +271,7 @@ data = (SV *) ctxt->context->funcLookupData; if (ctxt->context->funcLookupData == NULL || !SvROK(data) || SvTYPE(SvRV(data)) != SVt_PVHV) { - croak("XPathContext: lost function lookup data structure!\n"); + croak("XPathContext: lost function lookup data structure!"); } function = ctxt->context->function; @@ -289,7 +289,7 @@ hv_fetch((HV*)SvRV(data), strkey, len, 0); if ( perl_function == NULL || !SvROK(*perl_function) || SvTYPE(SvRV(*perl_function)) != SVt_PVCV ) { - croak("XPathContext: lost perl extension function!\n"); + croak("XPathContext: lost perl extension function!"); } SvREFCNT_dec(key); @@ -384,10 +384,10 @@ if (SvTRUE(ERRSV)) { POPs; - croak("XPathContext: error coming back from perl-dispatcher in pm file. %s\n", SvPV_nolen(ERRSV)); + croak("XPathContext: error coming back from perl-dispatcher in pm file. %s", SvPV_nolen(ERRSV)); } - if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned more than one argument!\n"); + if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned more than one argument!"); ret = LibXML_perldata_to_LibXMLdata(ctxt, POPs); @@ -495,7 +495,7 @@ INIT: xmlXPathContextPtr ctxt = (xmlXPathContextPtr)SvIV(SvRV(self)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); CODE: @@ -504,7 +504,7 @@ PmmOWNERPO( PmmPROXYNODE(ctxt->node))); } else { - warn("XPathContext: lost context node\n"); + croak("XPathContext: lost context node"); RETVAL = &PL_sv_undef; } OUTPUT: @@ -517,7 +517,7 @@ INIT: xmlXPathContextPtr ctxt = (xmlXPathContextPtr)SvIV(SvRV(self)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } PPCODE: if (XPathContextDATA(ctxt)->node) { @@ -537,13 +537,13 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); PPCODE: ret = xmlXPathRegisterNs(ctxt, prefix, ns_uri); if(ret == -1) { - croak( "cannot register ns" ); + croak("XPathContext:cannot register namespace"); } SV* @@ -553,7 +553,7 @@ SV ** lookup_data; xmlXPathContextPtr ctxt = (xmlXPathContextPtr)SvIV(SvRV(self)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); CODE: @@ -587,7 +587,7 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) { @@ -595,7 +595,7 @@ av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_func)); av_push((AV *)SvRV(pfdr), SvREFCNT_inc(lookup_data)); } else { - croak( "1st argument is not a CODE reference" ); + croak("XPathContext: 1st argument is not a CODE reference"); } if (ctxt->varLookupData != NULL) { if (SvTYPE(SvRV((SV *)ctxt->varLookupData)) == SVt_PVAV) { @@ -603,13 +603,13 @@ ctxt->varLookupData = NULL; ctxt->varLookupFunc = NULL; } else { - croak("can't register: varLookupData slot already occupied\n"); + croak("XPathContext: cannot register: varLookupData slot already occupied"); } } PPCODE: xmlXPathRegisterVariableLookup(ctxt, LibXML_generic_variable_lookup, pfdr); if (ctxt->varLookupData==NULL || ctxt->varLookupData != pfdr) { - croak( "registrating failed\n" ); + croak( "XPathContext: registration failure" ); } void @@ -628,7 +628,7 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); if ( SvTYPE(SvRV(func)) == SVt_PVCV ) { @@ -640,7 +640,7 @@ /* good, it's a HV */ pfdr = (SV *)ctxt->funcLookupData; } else { - croak ( "can't register: funcLookupData structure occupied\n" ); + croak ("XPathContext: cannot register: funcLookupData structure occupied"); } } key = newSVpvn("",0); @@ -655,7 +655,7 @@ hv_store((HV *)SvRV(pfdr),strkey, len, SvREFCNT_inc(func), 0); SvREFCNT_dec(key); } else { - croak( "function is not a CODE reference\n" ); + croak("XPathContext: 3rd argument is not a CODE reference"); } PPCODE: if (SvOK(uri)) { @@ -674,11 +674,11 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "XPathContext: missing xpath context" ); + croak("XPathContext: missing xpath context"); } PPCODE: if ( XPathContextDATA(ctxt)->lock != 0 ) { - croak( "XPathContext: context is locked" ); + croak("XPathContext: context is locked"); } XPathContextDATA(ctxt)->lock=1; @@ -690,7 +690,7 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } PPCODE: XPathContextDATA(ctxt)->lock=0; @@ -713,18 +713,17 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); if ( ctxt->node == NULL ) { - croak( "lost node" ); + croak("XPathContext: lost current node"); } xpath = nodeSv2C(perl_xpath, ctxt->node); if ( !(xpath && xmlStrlen(xpath)) ) { - xs_warn( "bad xpath\n" ); if ( xpath ) xmlFree(xpath); - croak( "empty XPath found" ); + croak("XPathContext: empty XPath found"); XSRETURN_UNDEF; } PPCODE: @@ -806,18 +805,17 @@ INIT: ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context)); if ( ctxt == NULL ) { - croak( "missing xpath context" ); + croak("XPathContext: missing xpath context"); } LibXML_configure_xpathcontext(ctxt); if ( ctxt->node == NULL ) { - croak( "lost node" ); + croak("XPathContext: lost current node"); } xpath = nodeSv2C(pxpath, ctxt->node); if ( !(xpath && xmlStrlen(xpath)) ) { - xs_warn( "bad xpath\n" ); if ( xpath ) xmlFree(xpath); - croak( "empty XPath found" ); + croak("XPathContext: empty XPath found"); XSRETURN_UNDEF; } |
From: Ilya M. <m_...@us...> - 2003-03-24 09:26:54
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv3546 Modified Files: XPathContext.xs Log Message: Add missing 'static' declarations Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- XPathContext.xs 23 Mar 2003 20:00:10 -0000 1.20 +++ XPathContext.xs 24 Mar 2003 09:26:48 -0000 1.21 @@ -49,7 +49,7 @@ * **************************************************************** */ /* stores libxml errors into $@ */ -void +static void LibXML_error_handler(void * ctxt, const char * msg, ...) { va_list args; @@ -78,8 +78,8 @@ /* Stores pnode in context node-pool hash table in order to preserve */ /* at least one reference. */ /* If pnode is NULL, only return current value for hashkey */ -static -SV* LibXML_XPathContext_pool ( xmlXPathContextPtr ctxt, int hashkey, SV * pnode ) { +static SV* +LibXML_XPathContext_pool ( xmlXPathContextPtr ctxt, int hashkey, SV * pnode ) { SV ** value; HV * pool; SV * key; @@ -113,7 +113,7 @@ } /* convert perl result structures to LibXML structures */ -xmlXPathObjectPtr +static xmlXPathObjectPtr LibXML_perldata_to_LibXMLdata(xmlXPathParserContextPtr ctxt, SV* perl_result) { if (!SvOK(perl_result)) { |
From: Ilya M. <m_...@us...> - 2003-03-23 20:00:16
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv14591 Modified Files: XPathContext.xs Log Message: Cosmetic fixes Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- XPathContext.xs 23 Mar 2003 18:24:36 -0000 1.19 +++ XPathContext.xs 23 Mar 2003 20:00:10 -0000 1.20 @@ -122,7 +122,7 @@ if (SvROK(perl_result) && SvTYPE(SvRV(perl_result)) == SVt_PVAV) { /* consider any array ref to be a nodelist */ - int i = 0; + int i; int length; SV ** pnode; AV * array_result; @@ -132,7 +132,7 @@ ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet((xmlNodePtr) NULL); array_result = (AV*)SvRV(perl_result); length = av_len(array_result); - for( i; i <= length ; i++ ) { + for( i = 0; i <= length ; i++ ) { pnode = av_fetch(array_result,i,0); if (pnode != NULL && sv_isobject(*pnode) && sv_derived_from(*pnode,"XML::LibXML::Node")) { @@ -166,34 +166,26 @@ return ret; } else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { - int tmp_int; - /* warn("result is a boolean\n"); */ - tmp_int = SvIV(SvRV(perl_result)); - return (xmlXPathObjectPtr)xmlXPathNewBoolean(tmp_int); + return (xmlXPathObjectPtr) + xmlXPathNewBoolean(SvIV(SvRV(perl_result))); } else if (sv_isa(perl_result, "XML::LibXML::Literal")) { - char * tmp_string; - STRLEN n_a; - /* warn("result is a literal\n"); */ - tmp_string = SvPV(SvRV(perl_result), n_a); - return (xmlXPathObjectPtr)xmlXPathNewCString(tmp_string); + return (xmlXPathObjectPtr) + xmlXPathNewCString(SvPV_nolen(SvRV(perl_result))); } else if (sv_isa(perl_result, "XML::LibXML::Number")) { - double tmp_double; - - /* warn("result is a number\n"); */ - tmp_double = SvNV(SvRV(perl_result)); - return (xmlXPathObjectPtr)xmlXPathNewFloat(tmp_double); + return (xmlXPathObjectPtr) + xmlXPathNewFloat(SvNV(SvRV(perl_result))); } } else if (SvNOK(perl_result) || SvIOK(perl_result)) { /* warn("result is an unblessed number\n"); */ return (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); } else { /* warn("result is an unblessed string\n"); */ - STRLEN n_a; - return (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, n_a)); + return (xmlXPathObjectPtr) + xmlXPathNewCString(SvPV_nolen(perl_result)); } } @@ -211,10 +203,7 @@ SV ** lookup_func; SV ** lookup_data; I32 count; - STRLEN n_a; - SV * perl_result; dSP; - int tmp_int; SV * data; SV ** fetch; @@ -244,12 +233,11 @@ SPAGAIN; if (SvTRUE(ERRSV)) { POPs; - croak("XPathContext: error coming back from variable lookup function. %s\n", SvPV(ERRSV, n_a)); + croak("XPathContext: error coming back from variable lookup function. %s\n", SvPV_nolen(ERRSV)); } if (count != 1) croak("XPathContext: variable lookup function returned more than one argument!\n"); - perl_result = POPs; - ret = LibXML_perldata_to_LibXMLdata(NULL, perl_result); + ret = LibXML_perldata_to_LibXMLdata(NULL, POPs); PUTBACK; FREETMPS; @@ -270,9 +258,7 @@ SV * perl_dispatch; int i; STRLEN len; - SV * perl_result; ProxyNodePtr owner = NULL; - STRLEN n_a; SV *key; char *strkey; const char *function, *uri; @@ -398,13 +384,12 @@ if (SvTRUE(ERRSV)) { POPs; - croak("XPathContext: error coming back from perl-dispatcher in pm file. %s\n", SvPV(ERRSV, n_a)); + croak("XPathContext: error coming back from perl-dispatcher in pm file. %s\n", SvPV_nolen(ERRSV)); } if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned more than one argument!\n"); - perl_result = POPs; - ret = LibXML_perldata_to_LibXMLdata(ctxt, perl_result); + ret = LibXML_perldata_to_LibXMLdata(ctxt, POPs); valuePush(ctxt, ret); PUTBACK; |
From: Ilya M. <m_...@us...> - 2003-03-23 18:24:39
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv16118 Modified Files: XPathContext.xs Log Message: Remove unused vars Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- XPathContext.xs 23 Mar 2003 18:22:36 -0000 1.18 +++ XPathContext.xs 23 Mar 2003 18:24:36 -0000 1.19 @@ -213,11 +213,7 @@ I32 count; STRLEN n_a; SV * perl_result; - AV * array_result; - xmlNodePtr tmp_node, tmp_node1; dSP; - char * tmp_string; - double tmp_double; int tmp_int; SV * data; SV ** fetch; @@ -276,12 +272,7 @@ STRLEN len; SV * perl_result; ProxyNodePtr owner = NULL; - char * tmp_string; STRLEN n_a; - double tmp_double; - int tmp_int; - AV * array_result; - xmlNodePtr tmp_node; SV *key; char *strkey; const char *function, *uri; |
From: Ilya M. <m_...@us...> - 2003-03-23 18:22:39
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv15276 Modified Files: XPathContext.xs Log Message: Minor cleanup in LibXML_perldata_to_LibXMLdata (get rid of goto FINISH) Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- XPathContext.xs 23 Mar 2003 18:19:29 -0000 1.17 +++ XPathContext.xs 23 Mar 2003 18:22:36 -0000 1.18 @@ -116,11 +116,8 @@ xmlXPathObjectPtr LibXML_perldata_to_LibXMLdata(xmlXPathParserContextPtr ctxt, SV* perl_result) { - xmlXPathObjectPtr ret; - if (!SvOK(perl_result)) { - ret = (xmlXPathObjectPtr)xmlXPathNewCString(""); - goto FINISH; + return (xmlXPathObjectPtr)xmlXPathNewCString(""); } if (SvROK(perl_result) && SvTYPE(SvRV(perl_result)) == SVt_PVAV) { @@ -129,6 +126,7 @@ int length; SV ** pnode; AV * array_result; + xmlXPathObjectPtr ret; /* warn("result is a node list\n"); */ ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet((xmlNodePtr) NULL); @@ -148,12 +146,13 @@ warn("XPathContext: ignoring non-node member of a nodelist"); } } - goto FINISH; + return ret; } else if (sv_isobject(perl_result) && (SvTYPE(SvRV(perl_result)) == SVt_PVMG)) { if (sv_derived_from(perl_result, "XML::LibXML::Node")) { xmlNodePtr tmp_node; + xmlXPathObjectPtr ret; /* warn("result is a node\n"); */ ret = (xmlXPathObjectPtr)xmlXPathNewNodeSet(NULL); @@ -163,15 +162,15 @@ LibXML_XPathContext_pool(ctxt->context, (int) PmmSvNode(perl_result), perl_result); } - goto FINISH; + + return ret; } else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { int tmp_int; /* warn("result is a boolean\n"); */ tmp_int = SvIV(SvRV(perl_result)); - ret = (xmlXPathObjectPtr)xmlXPathNewBoolean(tmp_int); - goto FINISH; + return (xmlXPathObjectPtr)xmlXPathNewBoolean(tmp_int); } else if (sv_isa(perl_result, "XML::LibXML::Literal")) { char * tmp_string; @@ -179,29 +178,23 @@ /* warn("result is a literal\n"); */ tmp_string = SvPV(SvRV(perl_result), n_a); - ret = (xmlXPathObjectPtr)xmlXPathNewCString(tmp_string); - goto FINISH; + return (xmlXPathObjectPtr)xmlXPathNewCString(tmp_string); } else if (sv_isa(perl_result, "XML::LibXML::Number")) { double tmp_double; /* warn("result is a number\n"); */ tmp_double = SvNV(SvRV(perl_result)); - ret = (xmlXPathObjectPtr)xmlXPathNewFloat(tmp_double); - goto FINISH; + return (xmlXPathObjectPtr)xmlXPathNewFloat(tmp_double); } } else if (SvNOK(perl_result) || SvIOK(perl_result)) { /* warn("result is an unblessed number\n"); */ - ret = (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); + return (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); } else { /* warn("result is an unblessed string\n"); */ STRLEN n_a; - ret = (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, n_a)); + return (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, n_a)); } - - - FINISH: - return ret; } |
From: Ilya M. <m_...@us...> - 2003-03-23 18:19:32
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv14288 Modified Files: XPathContext.xs Log Message: Move common code from LibXML_generic_variable_lookup and LibXML_generic_extension_function to LibXML_perldata_to_LibXMLdata Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- XPathContext.xs 21 Mar 2003 20:11:03 -0000 1.16 +++ XPathContext.xs 23 Mar 2003 18:19:29 -0000 1.17 @@ -112,72 +112,23 @@ } } -/* **************************************************************** - * Variable Lookup - * **************************************************************** */ -/* Much of the code is borrowed from Matt Sergeant's XML::LibXSLT */ -static xmlXPathObjectPtr -LibXML_generic_variable_lookup(void* varLookupData, - const xmlChar *name, - const xmlChar *ns_uri) -{ +/* convert perl result structures to LibXML structures */ +xmlXPathObjectPtr +LibXML_perldata_to_LibXMLdata(xmlXPathParserContextPtr ctxt, + SV* perl_result) { xmlXPathObjectPtr ret; - SV ** lookup_func; - SV ** lookup_data; - I32 count; - STRLEN n_a; - SV * perl_result; - AV * array_result; - xmlNodePtr tmp_node, tmp_node1; - dSP; - char * tmp_string; - double tmp_double; - int tmp_int; - SV * data; - SV ** fetch; - data = (SV *) varLookupData; - if (varLookupData == NULL || !SvROK(data) || - SvTYPE(SvRV(data)) != SVt_PVAV) { - croak("XPathContext: lost variable lookup data structure!\n"); - } - - lookup_func = av_fetch((AV *) SvRV(data),0,0 ); - if ( lookup_func == NULL || !SvROK(*lookup_func) || SvTYPE(SvRV(*lookup_func)) != SVt_PVCV ) { - croak("XPathContext: lost variable lookup function!\n"); - } - lookup_data = av_fetch((AV *) SvRV(data),1,0 ); - - ENTER; - SAVETMPS; - PUSHMARK(SP); - - XPUSHs( (lookup_data != NULL) ? *lookup_data : &PL_sv_undef ); - XPUSHs(sv_2mortal(C2Sv(name,NULL))); - XPUSHs(sv_2mortal(C2Sv(ns_uri,NULL))); - PUTBACK ; - - count = perl_call_sv(*lookup_func, G_SCALAR|G_EVAL); - - SPAGAIN; - if (SvTRUE(ERRSV)) { - POPs; - croak("XPathContext: error coming back from variable lookup function. %s\n", SvPV(ERRSV, n_a)); - } - if (count != 1) croak("XPathContext: variable lookup function returned more than one argument!\n"); - - perl_result = POPs; if (!SvOK(perl_result)) { ret = (xmlXPathObjectPtr)xmlXPathNewCString(""); goto FINISH; } - /* convert perl result structures to LibXML structures */ if (SvROK(perl_result) && SvTYPE(SvRV(perl_result)) == SVt_PVAV) { /* consider any array ref to be a nodelist */ int i = 0; int length; SV ** pnode; + AV * array_result; /* warn("result is a node list\n"); */ ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet((xmlNodePtr) NULL); @@ -189,6 +140,10 @@ sv_derived_from(*pnode,"XML::LibXML::Node")) { xmlXPathNodeSetAdd(ret->nodesetval, (xmlNodePtr)PmmSvNode(*pnode)); + if(ctxt) { + LibXML_XPathContext_pool(ctxt->context, + (int) PmmSvNode(*pnode), *pnode); + } } else { warn("XPathContext: ignoring non-node member of a nodelist"); } @@ -198,25 +153,38 @@ (SvTYPE(SvRV(perl_result)) == SVt_PVMG)) { if (sv_derived_from(perl_result, "XML::LibXML::Node")) { + xmlNodePtr tmp_node; + /* warn("result is a node\n"); */ ret = (xmlXPathObjectPtr)xmlXPathNewNodeSet(NULL); tmp_node = (xmlNodePtr)PmmSvNode(perl_result); xmlXPathNodeSetAdd(ret->nodesetval,tmp_node); + if(ctxt) { + LibXML_XPathContext_pool(ctxt->context, (int) PmmSvNode(perl_result), + perl_result); + } goto FINISH; } else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { + int tmp_int; + /* warn("result is a boolean\n"); */ tmp_int = SvIV(SvRV(perl_result)); ret = (xmlXPathObjectPtr)xmlXPathNewBoolean(tmp_int); goto FINISH; } else if (sv_isa(perl_result, "XML::LibXML::Literal")) { + char * tmp_string; + STRLEN n_a; + /* warn("result is a literal\n"); */ tmp_string = SvPV(SvRV(perl_result), n_a); ret = (xmlXPathObjectPtr)xmlXPathNewCString(tmp_string); goto FINISH; } else if (sv_isa(perl_result, "XML::LibXML::Number")) { + double tmp_double; + /* warn("result is a number\n"); */ tmp_double = SvNV(SvRV(perl_result)); ret = (xmlXPathObjectPtr)xmlXPathNewFloat(tmp_double); @@ -227,11 +195,72 @@ ret = (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); } else { /* warn("result is an unblessed string\n"); */ + STRLEN n_a; ret = (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, n_a)); } FINISH: + return ret; +} + + +/* **************************************************************** + * Variable Lookup + * **************************************************************** */ +/* Much of the code is borrowed from Matt Sergeant's XML::LibXSLT */ +static xmlXPathObjectPtr +LibXML_generic_variable_lookup(void* varLookupData, + const xmlChar *name, + const xmlChar *ns_uri) +{ + xmlXPathObjectPtr ret; + SV ** lookup_func; + SV ** lookup_data; + I32 count; + STRLEN n_a; + SV * perl_result; + AV * array_result; + xmlNodePtr tmp_node, tmp_node1; + dSP; + char * tmp_string; + double tmp_double; + int tmp_int; + SV * data; + SV ** fetch; + + data = (SV *) varLookupData; + if (varLookupData == NULL || !SvROK(data) || + SvTYPE(SvRV(data)) != SVt_PVAV) { + croak("XPathContext: lost variable lookup data structure!\n"); + } + + lookup_func = av_fetch((AV *) SvRV(data),0,0 ); + if ( lookup_func == NULL || !SvROK(*lookup_func) || SvTYPE(SvRV(*lookup_func)) != SVt_PVCV ) { + croak("XPathContext: lost variable lookup function!\n"); + } + lookup_data = av_fetch((AV *) SvRV(data),1,0 ); + + ENTER; + SAVETMPS; + PUSHMARK(SP); + + XPUSHs( (lookup_data != NULL) ? *lookup_data : &PL_sv_undef ); + XPUSHs(sv_2mortal(C2Sv(name,NULL))); + XPUSHs(sv_2mortal(C2Sv(ns_uri,NULL))); + PUTBACK ; + + count = perl_call_sv(*lookup_func, G_SCALAR|G_EVAL); + + SPAGAIN; + if (SvTRUE(ERRSV)) { + POPs; + croak("XPathContext: error coming back from variable lookup function. %s\n", SvPV(ERRSV, n_a)); + } + if (count != 1) croak("XPathContext: variable lookup function returned more than one argument!\n"); + + perl_result = POPs; + ret = LibXML_perldata_to_LibXMLdata(NULL, perl_result); PUTBACK; FREETMPS; @@ -391,75 +420,8 @@ if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned more than one argument!\n"); perl_result = POPs; - if (!SvOK(perl_result)) { - /* warn("result is a empty\n"); */ - ret = (xmlXPathObjectPtr)xmlXPathNewCString(""); - goto FINISH; - } - - /* convert perl result structures to LibXML structures */ - if (SvROK(perl_result) && - SvTYPE(SvRV(perl_result)) == SVt_PVAV) { - /* consider any array ref to be a nodelist */ - int length = 0; - SV ** pnode; - - /* warn("result is a node list\n"); */ - ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet((xmlNodePtr) NULL); - array_result = (AV*)SvRV(perl_result); - length = av_len(array_result); - for( i=0 ; i <= length ; i++ ) { - pnode = av_fetch(array_result,i,0); - if (pnode != NULL && sv_isobject(*pnode) && - sv_derived_from(*pnode,"XML::LibXML::Node")) { - xmlXPathNodeSetAdd(ret->nodesetval, - (xmlNodePtr)PmmSvNode(*pnode)); - LibXML_XPathContext_pool(ctxt->context, - (int) PmmSvNode(*pnode), *pnode); - } else { - warn("XPathContext: ignoring non-node member of a nodelist"); - } - } - goto FINISH; - } else if (sv_isobject(perl_result) && - (SvTYPE(SvRV(perl_result)) == SVt_PVMG)) - { - if (sv_derived_from(perl_result, "XML::LibXML::Node")) { - /* warn("result is a node\n"); */ - ret = (xmlXPathObjectPtr)xmlXPathNewNodeSet(NULL); - tmp_node = (xmlNodePtr)PmmSvNode(perl_result); - xmlXPathNodeSetAdd(ret->nodesetval,tmp_node); - LibXML_XPathContext_pool(ctxt->context, (int) PmmSvNode(perl_result), - perl_result); - goto FINISH; - } - else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { - /* warn("result is a boolean\n"); */ - tmp_int = SvIV(SvRV(perl_result)); - ret = (xmlXPathObjectPtr)xmlXPathNewBoolean(tmp_int); - goto FINISH; - } - else if (sv_isa(perl_result, "XML::LibXML::Literal")) { - /* warn("result is a literal\n"); */ - tmp_string = SvPV(SvRV(perl_result), len); - ret = (xmlXPathObjectPtr)xmlXPathNewCString(tmp_string); - goto FINISH; - } - else if (sv_isa(perl_result, "XML::LibXML::Number")) { - /* warn("result is a number\n"); */ - tmp_double = SvNV(SvRV(perl_result)); - ret = (xmlXPathObjectPtr)xmlXPathNewFloat(tmp_double); - goto FINISH; - } - } else if (SvNOK(perl_result) || SvIOK(perl_result)) { - /* warn("result is an unblessed number\n"); */ - ret = (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result)); - } else { - /* warn("result is an unblessed string\n"); */ - ret = (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, n_a)); - } + ret = LibXML_perldata_to_LibXMLdata(ctxt, perl_result); - FINISH: valuePush(ctxt, ret); PUTBACK; FREETMPS; |
From: Petr P. <pa...@us...> - 2003-03-21 20:21:14
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext/t In directory sc8-pr-cvs1:/tmp/cvs-serv3691/t Modified Files: 02-functions.t Log Message: - fixed bug with wrong owner assignment for non-context document nodes - regression test for non-context document nodes added Index: 02-functions.t =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/t/02-functions.t,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- 02-functions.t 21 Mar 2003 16:27:49 -0000 1.4 +++ 02-functions.t 21 Mar 2003 20:11:02 -0000 1.5 @@ -1,6 +1,6 @@ # -*- cperl -*- use Test; -BEGIN { plan tests => 22 }; +BEGIN { plan tests => 23 }; use XML::LibXML; use XML::LibXML::XPathContext; @@ -67,12 +67,13 @@ $xc->registerFunction('new-chunk', sub { - XML::LibXML->new->parse_string('<x><a/><a/><a/></x>')->find('//*') + XML::LibXML->new->parse_string('<x><y><a/><a/></y><y><a/></y></x>')->find('//a') }); -ok($xc->findnodes('new-chunk()')->size() == 4); +ok($xc->findnodes('new-chunk()')->size() == 3); my ($x)=$xc->findnodes('new-chunk()/parent::*'); -ok($x->nodeName() eq 'x'); -ok($xc->findvalue('name(new-chunk()/parent::*)') eq 'x'); +ok($x->nodeName() eq 'y'); +ok($xc->findvalue('name(new-chunk()/parent::*)') eq 'y'); +ok($xc->findvalue('count(new-chunk()/parent::*)=2')); my $largedoc=XML::LibXML->new->parse_string('<a>'.('<b/>' x 3000).'</a>'); $xc->setContextNode($largedoc); |
From: Petr P. <pa...@us...> - 2003-03-21 20:17:17
|
Update of /cvsroot/perl-xml/XML-LibXML-XPathContext In directory sc8-pr-cvs1:/tmp/cvs-serv3691 Modified Files: XPathContext.xs Log Message: - fixed bug with wrong owner assignment for non-context document nodes - regression test for non-context document nodes added Index: XPathContext.xs =================================================================== RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- XPathContext.xs 21 Mar 2003 16:05:01 -0000 1.15 +++ XPathContext.xs 21 Mar 2003 20:11:03 -0000 1.16 @@ -322,8 +322,10 @@ len = nodelist->nodeNr; for( j ; j < len; j++){ tnode = nodelist->nodeTab[j]; - if( tnode != NULL && tnode->doc != NULL) { - owner = SvPROXYNODE(sv_2mortal(PmmNodeToSv((xmlNodePtr)(tnode->doc), NULL))); + if( tnode != NULL && tnode->doc != NULL) { + owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); + } else { + owner = NULL; } if (tnode->type == XML_NAMESPACE_DECL) { element = sv_newmortal(); @@ -819,7 +821,6 @@ int i = 0 ; const char * cls = "XML::LibXML::Node"; xmlNodePtr tnode; - owner = PmmOWNERPO(PmmNewNode(ctxt->node)); len = nodelist->nodeNr; for( i ; i < len; i++){ /* we have to create a new instance of an objectptr. @@ -843,6 +844,11 @@ } } else { + if (tnode->doc) { + owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); + } else { + owner = NULL; /* self contained node */ + } element = PmmNodeToSv(tnode, owner); } XPUSHs( sv_2mortal(element) ); @@ -917,7 +923,6 @@ xmlNodePtr tnode; SV * element; - owner = PmmOWNERPO(PmmNewNode(ctxt->node)); len = nodelist->nodeNr; for( i ; i < len; i++){ /* we have to create a new instance of an @@ -944,6 +949,11 @@ } } else { + if (tnode->doc) { + owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); + } else { + owner = NULL; /* self contained node */ + } element = PmmNodeToSv(tnode, owner); } XPUSHs( sv_2mortal(element) ); |