LibXML.xs

filter: Statementstmt 82.7% 3254 / 3932 Branchbran 61.3% 1671 / 2724 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 73.9% 4925 / 6656 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« dom.c ↑ Summary perl-libxml-mm.c »
1 /* $Id$
2 *
3 * This is free software, you may use it and distribute it under the same terms as
4 * Perl itself.
5 *
6 * Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7 */
8  
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12  
13 #if defined(_MSC_VER)
14 #define _CRT_SECURE_NO_DEPRECATE 1
15 #define _CRT_NONSTDC_NO_DEPRECATE 1
16 #endif
17  
18 /* perl stuff */
19 #include "EXTERN.h"
20 #include "perl.h"
21 #include "XSUB.h"
22 #define NEED_newRV_noinc_GLOBAL
23 #define NEED_sv_2pv_flags
24 #include "ppport.h"
25 #include "Av_CharPtrPtr.h" /* XS_*_charPtrPtr() */
26  
27 #include <fcntl.h>
28 #include <limits.h> /* INT_MAX */
29  
30 #ifndef WIN32
31 #include <unistd.h>
32 #endif
33  
34 /* libxml2 configuration properties */
35 #include <libxml/xmlversion.h>
36  
37 #define DEBUG_C14N
38  
39 /* libxml2 stuff */
40 #include <libxml/xmlversion.h>
41 #include <libxml/globals.h>
42 #include <libxml/xmlmemory.h>
43 #include <libxml/parser.h>
44 #include <libxml/parserInternals.h>
45 #include <libxml/HTMLparser.h>
46 #include <libxml/HTMLtree.h>
47 #include <libxml/c14n.h>
48 #include <libxml/tree.h>
49 #include <libxml/xpath.h>
50 #include <libxml/xpathInternals.h>
51 #include <libxml/xmlIO.h>
52 /* #include <libxml/debugXML.h> */
53 #include <libxml/xmlerror.h>
54 #include <libxml/xinclude.h>
55 #include <libxml/valid.h>
56  
57 #ifdef LIBXML_PATTERN_ENABLED
58 #include <libxml/pattern.h>
59 #endif
60  
61 #ifdef LIBXML_REGEXP_ENABLED
62 #include <libxml/xmlregexp.h>
63 #endif
64  
65 #if LIBXML_VERSION >= 20510
66 #define HAVE_SCHEMAS
67 #include <libxml/relaxng.h>
68 #include <libxml/xmlschemas.h>
69 #endif
70  
71 #if LIBXML_VERSION >= 20621
72 #define WITH_SERRORS
73 #ifdef LIBXML_READER_ENABLED
74 #define HAVE_READER_SUPPORT
75 #include <libxml/xmlreader.h>
76 #endif
77 #endif
78  
79 #ifdef LIBXML_CATALOG_ENABLED
80 #include <libxml/catalog.h>
81 #endif
82  
83 #ifdef HAVE_READER_SUPPORT
84  
85 typedef enum {
86 XML_TEXTREADER_NONE = -1,
87 XML_TEXTREADER_START= 0,
88 XML_TEXTREADER_ELEMENT= 1,
89 XML_TEXTREADER_END= 2,
90 XML_TEXTREADER_EMPTY= 3,
91 XML_TEXTREADER_BACKTRACK= 4,
92 XML_TEXTREADER_DONE= 5,
93 XML_TEXTREADER_ERROR= 6
94 } xmlTextReaderState;
95  
96 typedef enum {
97 XML_TEXTREADER_NOT_VALIDATE = 0,
98 XML_TEXTREADER_VALIDATE_DTD = 1,
99 XML_TEXTREADER_VALIDATE_RNG = 2,
100 XML_TEXTREADER_VALIDATE_XSD = 4
101 } xmlTextReaderValidate;
102  
103 #endif /* HAVE_READER_SUPPORT */
104  
105 /* GDOME support
106 * libgdome installs only the core functions to the system.
107 * this is not enough for XML::LibXML <-> XML::GDOME conversion.
108 * therefore there is the need to ship as well the GDOME core headers.
109 */
110 #ifdef XML_LIBXML_GDOME_SUPPORT
111  
112 #include <libgdome/gdome.h>
113 #include <libgdome/gdome-libxml-util.h>
114  
115 #endif
116  
117  
118 #if LIBXML_VERSION < 20621
119 /* HTML_PARSE_RECOVER was added in libxml2 2.6.21 */
120 # define HTML_PARSE_RECOVER XML_PARSE_RECOVER
121 #endif
122  
123  
124 /* XML::LibXML stuff */
125 #include "perl-libxml-mm.h"
126 #include "perl-libxml-sax.h"
127  
128 #include "dom.h"
129 #include "xpath.h"
130 #include "xpathcontext.h"
131  
132 #ifdef __cplusplus
133 }
134 #endif
135  
136  
137 #define TEST_PERL_FLAG(flag) \
138 SvTRUE(get_sv(flag, FALSE)) ? 1 : 0
139  
140 #ifdef HAVE_READER_SUPPORT
141 #define LIBXML_READER_TEST_ELEMENT(reader,name,nsURI) \
142 (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) && \
143 ((!nsURI && !name) \
144 || \
145 (!nsURI && xmlStrcmp((const xmlChar*)name, xmlTextReaderConstName(reader) ) == 0 ) \
146 || \
147 (nsURI && xmlStrcmp((const xmlChar*)nsURI, xmlTextReaderConstNamespaceUri(reader))==0 \
148 && \
149 (!name || xmlStrcmp((const xmlChar*)name, xmlTextReaderConstLocalName(reader)) == 0)))
150 #endif
151  
152 /* this should keep the default */
153 static xmlExternalEntityLoader LibXML_old_ext_ent_loader = NULL;
154  
155 /* global external entity loader */
156 SV *EXTERNAL_ENTITY_LOADER_FUNC = (SV *)NULL;
157  
158 SV* PROXY_NODE_REGISTRY_MUTEX = NULL;
159  
160 /* ****************************************************************
161 * Error handler
162 * **************************************************************** */
163  
164 #ifdef WITH_SERRORS
165  
166 #define INIT_READER_ERROR_HANDLER(reader)
167  
168 #define PREINIT_SAVED_ERROR SV* saved_error = sv_2mortal(newSV(0));
169  
170 #define INIT_ERROR_HANDLER \
171 xmlSetGenericErrorFunc((void *)saved_error, \
172 (xmlGenericErrorFunc) LibXML_flat_handler); \
173 xmlSetStructuredErrorFunc((void *)saved_error, \
174 (xmlStructuredErrorFunc)LibXML_struct_error_handler)
175  
176 #define REPORT_ERROR(recover) LibXML_report_error_ctx(saved_error, recover)
177  
178 #define CLEANUP_ERROR_HANDLER xmlSetGenericErrorFunc(NULL,NULL); \
179 xmlSetStructuredErrorFunc(NULL,NULL)
180  
181 #else /* WITH_SERRORS */
182  
183 #define INIT_READER_ERROR_HANDLER(reader) \
184 if (reader) \
185 xmlTextReaderSetErrorHandler(reader, LibXML_reader_error_handler, \
186 sv_2mortal(newSVpv("",0)));
187  
188 #define PREINIT_SAVED_ERROR SV* saved_error = sv_2mortal(newSVpv("",0));
189  
190 #define INIT_ERROR_HANDLER \
191 xmlSetGenericErrorFunc((void *) saved_error, \
192 (xmlGenericErrorFunc) LibXML_error_handler_ctx)
193  
194 #define REPORT_ERROR(recover) LibXML_report_error_ctx(saved_error, recover)
195  
196 #define CLEANUP_ERROR_HANDLER xmlSetGenericErrorFunc(NULL,NULL);
197  
198  
199 #endif /* WITH_SERRORS */
200  
201 #ifdef WITH_SERRORS
202 void
203 338 LibXML_struct_error_callback(SV * saved_error, SV * libErr )
204 {
205  
206 dTHX;
207 338 dSP;
208  
209 338 ▶ if ( saved_error == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( saved_error == NULL ) { 0 338 338
210 0 warn( "have no save_error\n" );
211 }
212  
213 338 ENTER;
214 338 SAVETMPS;
215 338 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 338 338
216  
217 338 ▶ XPUSHs(sv_2mortal(libErr));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(libErr)); 0 338 338
218 338 ▶ if ( saved_error != NULL && SvOK(saved_error) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( saved_error != NULL && SvOK(saved_error) ) { 338 0 338
if ( saved_error != NULL && SvOK(saved_error) ) { 81 257 338
219 81 ▶ XPUSHs(saved_error);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(saved_error); 0 81 81
220 }
221 338 PUTBACK;
222  
223 338 ▶ if ( saved_error != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( saved_error != NULL ) { 338 0 338
224 338 call_pv( "XML::LibXML::Error::_callback_error", G_SCALAR | G_EVAL );
225 } else {
226 0 call_pv( "XML::LibXML::Error::_instant_error_callback", G_SCALAR );
227 }
228 338 SPAGAIN;
229  
230 338 ▶ if ( SvTRUE(ERRSV) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( SvTRUE(ERRSV) ) { 338 0 338
if ( SvTRUE(ERRSV) ) { 0 338 338
231 0 (void) POPs;
232 0 croak_obj;
233 } else {
234 338 sv_setsv(saved_error, POPs);
235 }
236  
237 338 PUTBACK;
238 338 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 338 0 338
239 338 LEAVE;
240 338 }
241  
242 void
243 338 LibXML_struct_error_handler(SV * saved_error, xmlErrorPtr error )
244 {
245 338 const char * CLASS = "XML::LibXML::LibError";
246 SV* libErr;
247  
248 338 libErr = NEWSV(0,0);
249 338 sv_setref_pv( libErr, CLASS, (void*)error );
250 338 LibXML_struct_error_callback( saved_error, libErr);
251 338 }
252  
253  
254 void
255 0 LibXML_flat_handler(SV * saved_error, const char * msg, ...)
256 {
257 SV* sv;
258 va_list args;
259  
260 0 sv = newSVpv("",0);
261 0 va_start(args, msg);
262 0 sv_vcatpvf(sv, msg, &args);
263 0 va_end(args);
264 xs_warn("flat error\n");
265 0 LibXML_struct_error_callback( saved_error, sv);
266 0 }
267  
268 #endif /* WITH_SERRORS */
269  
270  
271 /* If threads-support is working correctly in libxml2 then
272 * this method will be called with the correct thread-context */
273 void
274 0 LibXML_error_handler_ctx(void * ctxt, const char * msg, ...)
275 {
276 va_list args;
277 0 SV * saved_error = (SV *) ctxt;
278  
279 /* If saved_error is null we croak with the error */
280 0 ▶ if( NULL == saved_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if( NULL == saved_error ) { 0 0 0
281 0 SV * sv = sv_2mortal(newSV(0));
282 0 va_start(args, msg);
283 /* vfprintf(stderr, msg, args); */
284 0 sv_vsetpvfn(sv, msg, strlen(msg), &args, NULL, 0, NULL);
285 0 va_end(args);
286 0 croak("%s", SvPV_nolen(sv));
287 /* Otherwise, save the error */
288 } else {
289 0 va_start(args, msg);
290 /* vfprintf(stderr, msg, args); */
291 0 sv_vcatpvfn(saved_error, msg, strlen(msg), &args, NULL, 0, NULL);
292 0 va_end(args);
293 }
294 0 }
295  
296 static void
297 0 LibXML_validity_error_ctx(void * ctxt, const char *msg, ...)
298 {
299 va_list args;
300 0 SV * saved_error = (SV *) ctxt;
301  
302 /* If saved_error is null we croak with the error */
303 0 ▶ if( NULL == saved_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if( NULL == saved_error ) { 0 0 0
304 0 SV * sv = sv_2mortal(newSV(0));
305 0 va_start(args, msg);
306 0 sv_vsetpvfn(sv, msg, strlen(msg), &args, NULL, 0, NULL);
307 0 va_end(args);
308 0 croak("%s", SvPV_nolen(sv));
309 /* Otherwise, save the error */
310 } else {
311 0 va_start(args, msg);
312 0 sv_vcatpvfn(saved_error, msg, strlen(msg), &args, NULL, 0, NULL);
313 0 va_end(args);
314 }
315 0 }
316  
317 static void
318 0 LibXML_validity_warning_ctx(void * ctxt, const char *msg, ...)
319 {
320 va_list args;
321 0 SV * saved_error = (SV *) ctxt;
322 STRLEN len;
323  
324 /* If saved_error is null we croak with the error */
325 0 ▶ if( NULL == saved_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if( NULL == saved_error ) { 0 0 0
326 0 SV * sv = sv_2mortal(newSV(0));
327 0 va_start(args, msg);
328 0 sv_vsetpvfn(sv, msg, strlen(msg), &args, NULL, 0, NULL);
329 0 va_end(args);
330 0 croak("LibXML_validity_warning_ctx internal error: context was null (%s)", SvPV_nolen(sv));
331 /* Otherwise, give the warning */
332 } else {
333 0 va_start(args, msg);
334 0 sv_vcatpvfn(saved_error, msg, strlen(msg), &args, NULL, 0, NULL);
335 0 va_end(args);
336 0 warn("validation error: %s", SvPV(saved_error, len));
337 }
338 0 }
339  
340 static int
341 399 LibXML_will_die_ctx(SV * saved_error, int recover)
342 {
343 #ifdef WITH_SERRORS
344 399 ▶ if( saved_error!=NULL && SvOK(saved_error) ) {
Branch: 2 branches
BranchTrueFalseTotal
if( saved_error!=NULL && SvOK(saved_error) ) { 399 0 399
if( saved_error!=NULL && SvOK(saved_error) ) { 83 316 399
345 83 ▶ if ( recover == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( recover == 0 ) { 83 0 83
346 83 return 1;
347 }
348 }
349 #else
350 if( 0 < SvCUR( saved_error ) ) {
351 if ( recover == 0 ) {
352 return 1;
353 }
354 }
355 #endif
356 316 return 0;
357 }
358  
359  
360 static void
361 1851 LibXML_report_error_ctx(SV * saved_error, int recover)
362 {
363 #ifdef WITH_SERRORS
364 1851 ▶ if( saved_error!=NULL && SvOK( saved_error ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if( saved_error!=NULL && SvOK( saved_error ) ) { 1851 0 1851
if( saved_error!=NULL && SvOK( saved_error ) ) { 153 1698 1851
365 153 ▶ if (!recover || recover==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (!recover || recover==1) { 2 151 153
if (!recover || recover==1) { 1 1 2
366 dTHX;
367 152 dSP;
368  
369 152 ENTER;
370 152 SAVETMPS;
371 152 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 152 152
372 152 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 152 152
373 152 PUSHs(saved_error);
374 152 PUTBACK;
375 152 ▶ if (recover==1) {
Branch: 1 branch
BranchTrueFalseTotal
if (recover==1) { 1 151 152
376 1 call_pv( "XML::LibXML::Error::_report_warning", G_SCALAR | G_DISCARD);
377 } else {
378 151 call_pv( "XML::LibXML::Error::_report_error", G_SCALAR | G_DISCARD);
379 }
380 1 SPAGAIN;
381  
382 1 PUTBACK;
383 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 1 1
384 1 LEAVE;
385 }
386 }
387 #else
388 if( 0 < SvCUR( saved_error ) ) {
389 if( recover ) {
390 if ( recover == 1 ) {
391 warn("%s", SvPV_nolen(saved_error));
392 } /* else recover silently */
393 } else {
394 croak("%s", SvPV_nolen(saved_error));
395 }
396 }
397 #endif
398 1700 }
399  
400 #ifdef HAVE_READER_SUPPORT
401  
402 #ifndef WITH_SERRORS
403 static void
404 LibXML_reader_error_handler(void * ctxt,
405 const char * msg,
406 xmlParserSeverities severity,
407 xmlTextReaderLocatorPtr locator)
408 {
409 int line = xmlTextReaderLocatorLineNumber(locator);
410 xmlChar * filename = xmlTextReaderLocatorBaseURI(locator);
411 SV * msg_sv = sv_2mortal(C2Sv((xmlChar*) msg,NULL));
412 SV * error = sv_2mortal(newSVpv("", 0));
413  
414 switch (severity) {
415 case XML_PARSER_SEVERITY_VALIDITY_WARNING:
416 sv_catpv(error, "Validity WARNING");
417 break;
418 case XML_PARSER_SEVERITY_WARNING:
419 sv_catpv(error, "Reader WARNING");
420 break;
421 case XML_PARSER_SEVERITY_VALIDITY_ERROR:
422 sv_catpv(error, "Validity ERROR");
423 break;
424 case XML_PARSER_SEVERITY_ERROR:
425 sv_catpv(error, "Reader ERROR");
426 break;
427 }
428 if (filename) {
429 sv_catpvf(error, " in %s", filename);
430 xmlFree(filename);
431 }
432 if (line >= 0) {
433 sv_catpvf(error, " at line %d", line);
434 }
435 sv_catpvf(error, ": %s", SvPV_nolen(msg_sv));
436 if (severity == XML_PARSER_SEVERITY_VALIDITY_WARNING ||
437 severity == XML_PARSER_SEVERITY_WARNING ) {
438 warn("%s", SvPV_nolen(error));
439 } else {
440 SV * error_sv = (SV*) ctxt;
441 if (error_sv) {
442 sv_catpvf(error_sv, "%s ", SvPV_nolen(error));
443 } else {
444 croak("%s",SvPV_nolen(error));
445 }
446 }
447 }
448 #endif /* !defined WITH_SERRORS */
449  
450 SV *
451 0 LibXML_get_reader_error_data(xmlTextReaderPtr reader)
452 {
453 0 SV * saved_error = NULL;
454 0 xmlTextReaderErrorFunc f = NULL;
455 0 xmlTextReaderGetErrorHandler(reader, &f, (void **) &saved_error);
456 0 return saved_error;
457 }
458  
459 #ifndef WITH_SERRORS
460 static void
461 LibXML_report_reader_error(xmlTextReaderPtr reader)
462 {
463 SV * saved_error = NULL;
464 xmlTextReaderErrorFunc f = NULL;
465 xmlTextReaderGetErrorHandler(reader, &f, (void **) &saved_error);
466 if ( saved_error && SvOK( saved_error) && 0 < SvCUR( saved_error ) ) {
467 croak("%s", SvPV_nolen(saved_error));
468 }
469 }
470 #endif /* !defined WITH_SERRORS */
471  
472 #endif /* HAVE_READER_SUPPORT */
473  
474 static int
475 907 LibXML_get_recover(HV * real_obj)
476 {
477 907 SV** item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
478 907 ▶ return ( item != NULL && SvTRUE(*item) ) ? SvIV(*item) : 0;
Branch: 2 branches
BranchTrueFalseTotal
return ( item != NULL && SvTRUE(*item) ) ? SvIV(*item) : 0; 69 838 907
return ( item != NULL && SvTRUE(*item) ) ? SvIV(*item) : 0; 1 68 69
479 }
480  
481 static SV *
482 415 LibXML_NodeToSv(HV * real_obj, xmlNodePtr real_doc)
483 {
484 415 SV** item = hv_fetch( real_obj, "XML_LIBXML_GDOME", 16, 0 );
485  
486 415 ▶ if ( item != NULL && SvTRUE(*item) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( item != NULL && SvTRUE(*item) ) { 30 385 415
if ( item != NULL && SvTRUE(*item) ) { 0 30 30
487 0 return PmmNodeToGdomeSv(real_doc);
488 }
489 else {
490 415 return PmmNodeToSv(real_doc, NULL);
491 }
492 }
493  
494 /* ****************************************************************
495 * IO callbacks
496 * **************************************************************** */
497  
498 int
499 34 LibXML_read_perl (SV * ioref, char * buffer, int len)
500 {
501 dTHX;
502 34 dSP;
503  
504 int cnt;
505 SV * read_results;
506 IV read_results_iv;
507 STRLEN read_length;
508 char * chars;
509 34 SV * tbuff = NEWSV(0,len);
510 34 SV * tsize = newSViv(len);
511  
512 34 ENTER;
513 34 SAVETMPS;
514  
515 34 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 34 34
516 34 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 34 34
517 34 PUSHs(ioref);
518 34 PUSHs(sv_2mortal(tbuff));
519 34 PUSHs(sv_2mortal(tsize));
520 34 PUTBACK;
521  
522 34 ▶ if (sv_isobject(ioref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(ioref)) { 11 23 34
523 11 cnt = call_method("read", G_SCALAR | G_EVAL);
524 }
525 else {
526 23 cnt = call_pv("XML::LibXML::__read", G_SCALAR | G_EVAL);
527 }
528  
529 34 SPAGAIN;
530  
531 34 ▶ if (cnt != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (cnt != 1) { 0 34 34
532 0 croak("read method call failed");
533 }
534  
535 34 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 34 0 34
if (SvTRUE(ERRSV)) { 1 33 34
536 1 (void) POPs;
537 1 croak_obj;
538 }
539  
540 33 read_results = POPs;
541  
542 33 ▶ if (!SvOK(read_results)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(read_results)) { 0 33 33
543 0 croak("read error");
544 }
545  
546 33 read_results_iv = SvIV(read_results);
547  
548 33 chars = SvPV(tbuff, read_length);
549  
550 /*
551 * If the file handle uses an encoding layer, the length parameter is
552 * interpreted as character count, not as byte count. So it's possible
553 * that more than len bytes are read which would overflow the buffer.
554 * Check for this condition also by comparing the return value.
555 */
556 33 ▶ if (read_results_iv != read_length || read_length > len) {
Branch: 2 branches
BranchTrueFalseTotal
if (read_results_iv != read_length || read_length > len) { 32 1 33
if (read_results_iv != read_length || read_length > len) { 0 32 32
557 1 croak("Read more bytes than requested. Do you use an encoding-related"
558 " PerlIO layer?");
559 }
560 32 strncpy(buffer, chars, read_length);
561  
562 32 PUTBACK;
563 32 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 32 0 32
564 32 LEAVE;
565  
566 32 return read_length;
567 }
568  
569 /* used only by Reader */
570 int
571 1 LibXML_close_perl (SV * ioref)
572 {
573 1 SvREFCNT_dec(ioref);
574 1 return 0;
575 }
576  
577 int
578 116 LibXML_input_match(char const * filename)
579 {
580 int results;
581 int count;
582 SV * res;
583  
584 116 results = 0;
585  
586 {
587 dTHX;
588 116 dSP;
589  
590 116 ENTER;
591 116 SAVETMPS;
592  
593 116 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 116 116
594 116 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 116 116
595 116 PUSHs(sv_2mortal(newSVpv((char*)filename, 0)));
596 116 PUTBACK;
597  
598 116 count = call_pv("XML::LibXML::InputCallback::_callback_match",
599 G_SCALAR | G_EVAL);
600  
601 116 SPAGAIN;
602  
603 116 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 116 116
604 0 croak("match callback must return a single value");
605 }
606  
607 116 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 116 0 116
if (SvTRUE(ERRSV)) { 0 116 116
608 0 (void) POPs;
609 0 croak_obj;
610 }
611  
612 116 res = POPs;
613  
614 116 ▶ if (SvTRUE(res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(res)) { 25 91 116
615 25 results = 1;
616 }
617  
618 116 PUTBACK;
619 116 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 116 0 116
620 116 LEAVE;
621 }
622 116 return results;
623 }
624  
625 void *
626 25 LibXML_input_open(char const * filename)
627 {
628 SV * results;
629 int count;
630  
631 dTHX;
632 25 dSP;
633  
634 25 ENTER;
635 25 SAVETMPS;
636  
637 25 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 25 25
638 25 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 25 25
639 25 PUSHs(sv_2mortal(newSVpv((char*)filename, 0)));
640 25 PUTBACK;
641  
642 25 count = call_pv("XML::LibXML::InputCallback::_callback_open",
643 G_SCALAR | G_EVAL);
644  
645 25 SPAGAIN;
646  
647 25 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 25 25
648 0 croak("open callback must return a single value");
649 }
650  
651 25 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 25 0 25
if (SvTRUE(ERRSV)) { 0 25 25
652 0 (void) POPs;
653 0 croak_obj;
654 }
655  
656 25 results = POPs;
657  
658 25 (void)SvREFCNT_inc(results);
659  
660 25 PUTBACK;
661 25 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 25 0 25
662 25 LEAVE;
663  
664 25 return (void *)results;
665 }
666  
667 int
668 74 LibXML_input_read(void * context, char * buffer, int len)
669 {
670 STRLEN res_len;
671 const char * output;
672 SV * ctxt;
673 SV * output_sv;
674  
675 74 res_len = 0;
676 74 ctxt = (SV *)context;
677  
678 {
679 int count;
680  
681 dTHX;
682 74 dSP;
683  
684 74 ENTER;
685 74 SAVETMPS;
686  
687 74 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 74 74
688 74 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 74 74
689 74 PUSHs(ctxt);
690 74 PUSHs(sv_2mortal(newSViv(len)));
691 74 PUTBACK;
692  
693 74 count = call_pv("XML::LibXML::InputCallback::_callback_read",
694 G_SCALAR | G_EVAL);
695  
696 74 SPAGAIN;
697  
698 74 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 74 74
699 0 croak("read callback must return a single value");
700 }
701  
702 74 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 74 0 74
if (SvTRUE(ERRSV)) { 0 74 74
703 0 (void) POPs;
704 0 croak_obj;
705 }
706  
707 /*
708 * Handle undef()s gracefully, to avoid using POPpx which warns upon $^W
709 * being set. See t/49callbacks_returning_undef.t and:
710 * https://rt.cpan.org/Ticket/Display.html?id=70321
711 * */
712  
713 74 output_sv = POPs;
714 148 ▶ output = SvOK(output_sv) ? SvPV_nolen(output_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
output = SvOK(output_sv) ? SvPV_nolen(output_sv) : NULL; 74 0 74
715  
716 74 ▶ if (output != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (output != NULL) { 74 0 74
717 74 res_len = strlen(output);
718 74 ▶ if (res_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (res_len) { 49 25 74
719 49 strncpy(buffer, output, res_len);
720 }
721 else {
722 25 buffer[0] = 0;
723 }
724 }
725  
726 74 PUTBACK;
727 74 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 74 0 74
728 74 LEAVE;
729 }
730 74 return res_len;
731 }
732  
733 void
734 25 LibXML_input_close(void * context)
735 {
736 SV * ctxt;
737  
738 25 ctxt = (SV *)context;
739  
740 {
741 dTHX;
742 25 dSP;
743  
744 25 ENTER;
745 25 SAVETMPS;
746  
747 25 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 25 25
748 25 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 25 25
749 25 PUSHs(ctxt);
750 25 PUTBACK;
751  
752 25 call_pv("XML::LibXML::InputCallback::_callback_close",
753 G_SCALAR | G_EVAL | G_DISCARD);
754  
755 25 SvREFCNT_dec(ctxt);
756  
757 25 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 25 0 25
if (SvTRUE(ERRSV)) { 0 25 25
758 0 croak_obj;
759 }
760  
761 25 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 25 25
762 25 LEAVE;
763 }
764 25 }
765  
766 int
767 1 LibXML_output_write_handler(void * ioref, char * buffer, int len)
768 {
769 1 ▶ if ( buffer != NULL && len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( buffer != NULL && len > 0) { 1 0 1
if ( buffer != NULL && len > 0) { 1 0 1
770 dTHX;
771 1 dSP;
772  
773 1 SV * tbuff = newSVpv(buffer,len);
774 1 SV * tsize = newSViv(len);
775  
776  
777 1 ENTER;
778 1 SAVETMPS;
779  
780 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
781 1 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 1 1
782 1 PUSHs((SV*)ioref);
783 1 PUSHs(sv_2mortal(tbuff));
784 1 PUSHs(sv_2mortal(tsize));
785 1 PUTBACK;
786  
787 1 call_pv("XML::LibXML::__write", G_SCALAR | G_EVAL | G_DISCARD );
788  
789 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
790 0 croak_obj;
791 }
792  
793 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
794 1 LEAVE;
795 }
796 1 return len;
797 }
798  
799 int
800 1 LibXML_output_close_handler( void * handler )
801 {
802 1 return 1;
803 }
804  
805 xmlParserInputPtr
806 6 LibXML_load_external_entity(
807 const char * URL,
808 const char * ID,
809 xmlParserCtxtPtr ctxt)
810 {
811 SV ** func;
812 int count;
813 SV * results;
814 STRLEN results_len;
815 int int_results_len;
816 const char * results_pv;
817 xmlParserInputBufferPtr input_buf;
818  
819 6 ▶ if (ctxt->_private == NULL && EXTERNAL_ENTITY_LOADER_FUNC == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (ctxt->_private == NULL && EXTERNAL_ENTITY_LOADER_FUNC == NULL) 0 6 6
if (ctxt->_private == NULL && EXTERNAL_ENTITY_LOADER_FUNC == NULL) 0 0 0
820 {
821 0 return xmlNewInputFromFile(ctxt, URL);
822 }
823  
824 6 ▶ if (URL == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (URL == NULL) { 0 6 6
825 0 URL = "";
826 }
827 6 ▶ if (ID == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ID == NULL) { 3 3 6
828 3 ID = "";
829 }
830  
831 /* fetch entity loader function */
832 6 ▶ if(EXTERNAL_ENTITY_LOADER_FUNC != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(EXTERNAL_ENTITY_LOADER_FUNC != NULL) 2 4 6
833 {
834 2 func = &EXTERNAL_ENTITY_LOADER_FUNC;
835 }
836 else
837 {
838 SV * self;
839 HV * real_obj;
840  
841 4 self = (SV *)ctxt->_private;
842 4 real_obj = (HV *)SvRV(self);
843 4 func = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
844 }
845  
846 6 ▶ if (func != NULL && SvTRUE(*func)) {
Branch: 2 branches
BranchTrueFalseTotal
if (func != NULL && SvTRUE(*func)) { 6 0 6
if (func != NULL && SvTRUE(*func)) { 6 0 6
847 dTHX;
848 6 dSP;
849  
850 6 ENTER;
851 6 SAVETMPS;
852  
853 6 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 6 6
854 6 ▶ XPUSHs(sv_2mortal(newSVpv((char*)URL, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv((char*)URL, 0))); 0 6 6
855 6 ▶ XPUSHs(sv_2mortal(newSVpv((char*)ID, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv((char*)ID, 0))); 0 6 6
856 6 PUTBACK;
857  
858 6 count = call_sv(*func, G_SCALAR | G_EVAL);
859  
860 6 SPAGAIN;
861  
862 6 ▶ if (count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count == 0) { 0 6 6
863 0 croak("external entity handler did not return a value");
864 }
865  
866 6 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 6 0 6
if (SvTRUE(ERRSV)) { 0 6 6
867 0 (void) POPs;
868 0 croak_obj;
869 }
870  
871 6 results = POPs;
872  
873 6 results_pv = SvPV(results, results_len);
874 6 int_results_len = results_len;
875 6 ▶ if ((results_len > INT_MAX) || (int_results_len != results_len)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((results_len > INT_MAX) || (int_results_len != results_len)) { 6 0 6
if ((results_len > INT_MAX) || (int_results_len != results_len)) { 0 6 6
876 0 croak("a buffer would be too big\n");
877 }
878 6 input_buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
879 6 ▶ if (!input_buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (!input_buf) { 0 6 6
880 0 croak("cannot create a buffer!\n");
881 }
882 6 ▶ if (-1 == xmlParserInputBufferPush(input_buf, int_results_len, results_pv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-1 == xmlParserInputBufferPush(input_buf, int_results_len, results_pv)) { 0 6 6
883 0 xmlFreeParserInputBuffer(input_buf);
884 0 croak("cannot push an external entity into a buffer!\n");
885 }
886  
887 6 PUTBACK;
888 6 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 6 0 6
889 6 LEAVE;
890  
891 6 return xmlNewIOInputStream(ctxt, input_buf, XML_CHAR_ENCODING_NONE);
892 }
893 else {
894 0 ▶ if (URL == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (URL == NULL) { 0 0 0
895 0 return NULL;
896 }
897 0 return xmlNewInputFromFile(ctxt, URL);
898 }
899 }
900  
901 /* ****************************************************************
902 * Helper functions
903 * **************************************************************** */
904  
905 HV*
906 1012 LibXML_init_parser( SV * self, xmlParserCtxtPtr ctxt ) {
907 /* we fetch all switches and callbacks from the hash */
908 1012 HV* real_obj = NULL;
909 1012 SV** item = NULL;
910 1012 int parserOptions = XML_PARSE_NODICT;
911  
912 /* A NOTE ABOUT xmlInitParser(); */
913 /* xmlInitParser() should be used only at startup and*/
914 /* not for initializing a single parser. libxml2's */
915 /* documentation is quite clear about this. If */
916 /* something fails it is a problem elsewhere. Simply */
917 /* resetting the entire module will lead to unwanted */
918 /* results in server environments, such as if */
919 /* mod_perl is used together with php's xml module. */
920 /* calling xmlInitParser() here is definitely wrong! */
921 /* xmlInitParser(); */
922  
923 #ifndef WITH_SERRORS
924 xmlGetWarningsDefaultValue = 0;
925 #endif
926 1012 ▶ if ( self != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self != NULL ) { 1012 0 1012
927 /* first fetch the values from the hash */
928 1012 real_obj = (HV *)SvRV(self);
929  
930 1012 item = hv_fetch( real_obj, "XML_LIBXML_PARSER_OPTIONS", 25, 0 );
931 1012 ▶ if (item != NULL && SvOK(*item)) parserOptions = sv_2iv(*item);
Branch: 2 branches
BranchTrueFalseTotal
if (item != NULL && SvOK(*item)) parserOptions = sv_2iv(*item); 1012 0 1012
if (item != NULL && SvOK(*item)) parserOptions = sv_2iv(*item); 1012 0 1012
932  
933 /* compatibility with old implementation:
934 absence of XML_PARSE_DTDLOAD (load_ext_dtd) implies absence of
935 all DTD related flags
936 */
937 1012 ▶ if ((parserOptions & XML_PARSE_DTDLOAD) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((parserOptions & XML_PARSE_DTDLOAD) == 0) { 884 128 1012
938 884 parserOptions &= ~(XML_PARSE_DTDVALID | XML_PARSE_DTDATTR | XML_PARSE_NOENT );
939 }
940 1012 ▶ if (ctxt) xmlCtxtUseOptions(ctxt, parserOptions ); /* Note: sets ctxt->linenumbers = 1 */
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt) xmlCtxtUseOptions(ctxt, parserOptions ); /* Note: sets ctxt->linenumbers = 1 */ 542 470 1012
941  
942 /*
943 * Without this if/else conditional, NOBLANKS has no effect.
944 *
945 * For more information, see:
946 *
947 * https://rt.cpan.org/Ticket/Display.html?id=76696
948 *
949 * */
950 1012 ▶ if (parserOptions & XML_PARSE_NOBLANKS) {
Branch: 1 branch
BranchTrueFalseTotal
if (parserOptions & XML_PARSE_NOBLANKS) { 61 951 1012
951 61 xmlKeepBlanksDefault(0);
952 }
953 else {
954 951 xmlKeepBlanksDefault(1);
955 }
956  
957 1012 item = hv_fetch( real_obj, "XML_LIBXML_LINENUMBERS", 22, 0 );
958 1012 ▶ if ( item != NULL && SvTRUE(*item) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( item != NULL && SvTRUE(*item) ) { 75 937 1012
if ( item != NULL && SvTRUE(*item) ) { 2 73 75
959 2 ▶ if (ctxt) ctxt->linenumbers = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt) ctxt->linenumbers = 1; 2 0 2
960 }
961 else {
962 1010 ▶ if (ctxt) ctxt->linenumbers = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt) ctxt->linenumbers = 0; 540 470 1010
963 }
964  
965 1012 ▶ if(EXTERNAL_ENTITY_LOADER_FUNC == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(EXTERNAL_ENTITY_LOADER_FUNC == NULL) 1011 1 1012
966 {
967 1011 item = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
968 1011 ▶ if (item != NULL && SvTRUE(*item)) {
Branch: 2 branches
BranchTrueFalseTotal
if (item != NULL && SvTRUE(*item)) { 74 937 1011
if (item != NULL && SvTRUE(*item)) { 3 71 74
969 3 LibXML_old_ext_ent_loader = xmlGetExternalEntityLoader();
970 3 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_load_external_entity );
971 }
972 else
973 {
974 1008 ▶ if (parserOptions & XML_PARSE_NONET)
Branch: 1 branch
BranchTrueFalseTotal
if (parserOptions & XML_PARSE_NONET) 1 1007 1008
975 {
976 1 LibXML_old_ext_ent_loader = xmlGetExternalEntityLoader();
977 1 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
978 }
979 /* LibXML_old_ext_ent_loader = NULL; */
980 }
981 }
982 }
983  
984 1012 return real_obj;
985 }
986  
987 void
988 1010 LibXML_cleanup_parser() {
989 #ifndef WITH_SERRORS
990 xmlGetWarningsDefaultValue = 0;
991 #endif
992 1010 ▶ if (EXTERNAL_ENTITY_LOADER_FUNC == NULL && LibXML_old_ext_ent_loader != NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (EXTERNAL_ENTITY_LOADER_FUNC == NULL && LibXML_old_ext_ent_loader != NULL) 1009 1 1010
if (EXTERNAL_ENTITY_LOADER_FUNC == NULL && LibXML_old_ext_ent_loader != NULL) 4 1005 1009
993 {
994 4 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_old_ext_ent_loader );
995 }
996 1010 }
997  
998 int
999 210 LibXML_test_node_name( xmlChar * name )
1000 {
1001 210 xmlChar * cur = name;
1002 210 int tc = 0;
1003 210 int len = 0;
1004  
1005 210 ▶ if ( cur == NULL || *cur == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( cur == NULL || *cur == 0 ) { 210 0 210
if ( cur == NULL || *cur == 0 ) { 0 210 210
1006 /* warn("name is empty" ); */
1007 0 return(0);
1008 }
1009  
1010 210 tc = domParseChar( cur, &len );
1011  
1012 210 ▶ if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) {
Branch: 19 branches
BranchTrueFalseTotal
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 210 0 210
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 184 26 210
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 156 28 184
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 156 26 182
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 1 155 156
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 1 26 27
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 1 1
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 26 26
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 26 0 26
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 26 184 210
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 26 26
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 0 0 0
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 26 0 26
if ( !( IS_LETTER( tc ) || (tc == '_') || (tc == ':')) ) { 26 0 26
1013 /* warn( "is not a letter\n" ); */
1014 26 return(0);
1015 }
1016  
1017 184 tc = 0;
1018 184 cur += len;
1019  
1020 866 ▶ while (*cur != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
while (*cur != 0 ) { 682 184 866
1021 682 tc = domParseChar( cur, &len );
1022  
1023 682 ▶ if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') ||
Branch: 24 branches
BranchTrueFalseTotal
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 682 0 682
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 615 67 682
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 603 12 615
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 603 67 670
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 1 602 603
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 1 67 68
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 1 0 1
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 1 67 68
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 1 1
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 67 0 67
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 67 615 682
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 67 67
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 67 0 67
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 66 1 67
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 55 11 66
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 56 11 67
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 56 0 56
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 55 1 56
if (!(IS_LETTER(tc) || IS_DIGIT(tc) || (tc == '_') || 0 0 0
1024 55 ▶ (tc == '-') || (tc == ':') || (tc == '.') ||
Branch: 2 branches
BranchTrueFalseTotal
(tc == '-') || (tc == ':') || (tc == '.') || 0 55 55
(tc == '-') || (tc == ':') || (tc == '.') || 0 0 0
1025 0 ▶ IS_COMBINING(tc) || IS_EXTENDER(tc)) ) {
Branch: 1 branch
BranchTrueFalseTotal
IS_COMBINING(tc) || IS_EXTENDER(tc)) ) { 0 0 0
1026 /* warn( "is not a letter\n" ); */
1027 0 return(0);
1028 }
1029 682 tc = 0;
1030 682 cur += len;
1031 }
1032  
1033 /* warn("name is ok"); */
1034 184 return(1);
1035 }
1036  
1037 /* Assumes that the node has a proxy. */
1038 static void
1039 35 LibXML_reparent_removed_node(xmlNodePtr node) {
1040 /*
1041 * Attribute nodes can't be added to document fragments. Adding
1042 * DTD nodes would cause a memory leak.
1043 */
1044 35 ▶ if (node->type != XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
if (node->type != XML_ATTRIBUTE_NODE 33 2 35
1045 33 ▶ && node->type != XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
&& node->type != XML_DTD_NODE) { 28 5 33
1046 28 ProxyNodePtr docfrag = PmmNewFragment(node->doc);
1047 28 xmlAddChild(PmmNODE(docfrag), node);
1048 28 PmmFixOwner(PmmPROXYNODE(node), docfrag);
1049 }
1050 35 }
1051  
1052 static void
1053 12 LibXML_set_int_subset(xmlDocPtr doc, xmlNodePtr dtd) {
1054 12 xmlNodePtr old_dtd = (xmlNodePtr)doc->intSubset;
1055 12 ▶ if (old_dtd == dtd) {
Branch: 1 branch
BranchTrueFalseTotal
if (old_dtd == dtd) { 0 12 12
1056 0 return;
1057 }
1058  
1059 12 ▶ if (old_dtd != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (old_dtd != NULL) { 12 0 12
1060 12 xmlUnlinkNode(old_dtd);
1061  
1062 12 ▶ if (PmmPROXYNODE(old_dtd) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (PmmPROXYNODE(old_dtd) == NULL) { 6 6 12
1063 6 xmlFreeDtd((xmlDtdPtr)old_dtd);
1064 }
1065 }
1066  
1067 12 doc->intSubset = (xmlDtdPtr)dtd;
1068 }
1069  
1070 /* ****************************************************************
1071 * XPathContext helper functions
1072 * **************************************************************** */
1073  
1074 /* Temporary node pool: *
1075 * Stores pnode in context node-pool hash table in order to preserve *
1076 * at least one reference. *
1077 * If pnode is NULL, only return current value for hashkey */
1078 static SV*
1079 6045 LibXML_XPathContext_pool ( xmlXPathContextPtr ctxt, void * hashkey, SV * pnode ) {
1080 SV ** value;
1081 SV * key;
1082 STRLEN len;
1083 char * strkey;
1084 dTHX;
1085  
1086 6045 ▶ if (XPathContextDATA(ctxt)->pool == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->pool == NULL) { 20 6025 6045
1087 20 ▶ if (pnode == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pnode == NULL) { 0 20 20
1088 0 return &PL_sv_undef;
1089 } else {
1090 xs_warn("initializing node pool");
1091 20 XPathContextDATA(ctxt)->pool = newHV();
1092 }
1093 }
1094  
1095 6045 key = newSViv(PTR2IV(hashkey));
1096 6045 strkey = SvPV(key, len);
1097 6045 ▶ if (pnode != NULL && !hv_exists(XPathContextDATA(ctxt)->pool,strkey,len)) {
Branch: 2 branches
BranchTrueFalseTotal
if (pnode != NULL && !hv_exists(XPathContextDATA(ctxt)->pool,strkey,len)) { 6045 0 6045
if (pnode != NULL && !hv_exists(XPathContextDATA(ctxt)->pool,strkey,len)) { 6043 2 6045
1098 6043 value = hv_store(XPathContextDATA(ctxt)->pool,strkey,len, SvREFCNT_inc(pnode),0);
1099 } else {
1100 2 value = hv_fetch(XPathContextDATA(ctxt)->pool,strkey,len, 0);
1101 }
1102 6045 SvREFCNT_dec(key);
1103  
1104 6045 ▶ if (value == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (value == NULL) { 0 6045 6045
1105 0 return &PL_sv_undef;
1106 } else {
1107 6045 return *value;
1108 }
1109 }
1110  
1111 /* convert perl result structures to LibXML structures */
1112 static xmlXPathObjectPtr
1113 52 LibXML_perldata_to_LibXMLdata(xmlXPathParserContextPtr ctxt,
1114 SV* perl_result) {
1115 dTHX;
1116  
1117 52 ▶ if (!SvOK(perl_result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(perl_result)) { 0 52 52
1118 0 return (xmlXPathObjectPtr)xmlXPathNewCString("");
1119 }
1120 52 ▶ if (SvROK(perl_result) &&
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(perl_result) && 40 12 52
1121 40 ▶ SvTYPE(SvRV(perl_result)) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
SvTYPE(SvRV(perl_result)) == SVt_PVAV) { 27 13 40
1122 /* consider any array ref to be a nodelist */
1123 int i;
1124 int length;
1125 SV ** pnode;
1126 AV * array_result;
1127 xmlXPathObjectPtr ret;
1128  
1129 27 ret = (xmlXPathObjectPtr) xmlXPathNewNodeSet(INT2PTR(xmlNodePtr,NULL));
1130 27 array_result = (AV*)SvRV(perl_result);
1131 27 length = av_len(array_result);
1132 9083 ▶ for( i = 0; i <= length ; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for( i = 0; i <= length ; i++ ) { 9056 27 9083
1133 9056 pnode = av_fetch(array_result,i,0);
1134 18112 ▶ if (pnode != NULL && sv_isobject(*pnode) &&
Branch: 1 branch
BranchTrueFalseTotal
if (pnode != NULL && sv_isobject(*pnode) && 9056 0 9056
1135 9056 sv_derived_from(*pnode,"XML::LibXML::Node")) {
1136 9056 xmlXPathNodeSetAdd(ret->nodesetval,
1137 9056 INT2PTR(xmlNodePtr,PmmSvNode(*pnode)));
1138 9056 ▶ if(ctxt) {
Branch: 1 branch
BranchTrueFalseTotal
if(ctxt) { 6043 3013 9056
1139 6043 LibXML_XPathContext_pool(ctxt->context,
1140 6043 PmmSvNode(*pnode), *pnode);
1141 }
1142 } else {
1143 0 warn("XPathContext: ignoring non-node member of a nodelist");
1144 }
1145 }
1146 27 return ret;
1147 25 ▶ } else if (sv_isobject(perl_result) &&
Branch: 1 branch
BranchTrueFalseTotal
} else if (sv_isobject(perl_result) && 13 12 25
1148 13 ▶ (SvTYPE(SvRV(perl_result)) == SVt_PVMG))
Branch: 1 branch
BranchTrueFalseTotal
(SvTYPE(SvRV(perl_result)) == SVt_PVMG)) 13 0 13
1149 {
1150 13 ▶ if (sv_derived_from(perl_result, "XML::LibXML::Node")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(perl_result, "XML::LibXML::Node")) { 11 2 13
1151 xmlNodePtr tmp_node;
1152 xmlXPathObjectPtr ret;
1153  
1154 11 ret = INT2PTR(xmlXPathObjectPtr,xmlXPathNewNodeSet(NULL));
1155 11 tmp_node = INT2PTR(xmlNodePtr,PmmSvNode(perl_result));
1156 11 xmlXPathNodeSetAdd(ret->nodesetval,tmp_node);
1157 11 ▶ if(ctxt) {
Branch: 1 branch
BranchTrueFalseTotal
if(ctxt) { 2 9 11
1158 2 LibXML_XPathContext_pool(ctxt->context, PmmSvNode(perl_result),
1159 perl_result);
1160 }
1161  
1162 11 return ret;
1163 }
1164 2 ▶ else if (sv_isa(perl_result, "XML::LibXML::Boolean")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_isa(perl_result, "XML::LibXML::Boolean")) { 0 2 2
1165 0 return (xmlXPathObjectPtr)
1166 0 xmlXPathNewBoolean(SvIV(SvRV(perl_result)));
1167 }
1168 2 ▶ else if (sv_isa(perl_result, "XML::LibXML::Literal")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_isa(perl_result, "XML::LibXML::Literal")) { 1 1 2
1169 1 return (xmlXPathObjectPtr)
1170 2 xmlXPathNewCString(SvPV_nolen(SvRV(perl_result)));
1171 }
1172 1 ▶ else if (sv_isa(perl_result, "XML::LibXML::Number")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_isa(perl_result, "XML::LibXML::Number")) { 1 0 1
1173 1 return (xmlXPathObjectPtr)
1174 xmlXPathNewFloat(SvNV(SvRV(perl_result)));
1175 }
1176 12 ▶ } else if (SvNOK(perl_result) || SvIOK(perl_result)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvNOK(perl_result) || SvIOK(perl_result)) { 9 3 12
} else if (SvNOK(perl_result) || SvIOK(perl_result)) { 0 9 9
1177 3 return (xmlXPathObjectPtr)xmlXPathNewFloat(SvNV(perl_result));
1178 } else {
1179 9 return (xmlXPathObjectPtr)
1180 9 xmlXPathNewCString(SvPV_nolen(perl_result));
1181 }
1182 0 return NULL;
1183 }
1184  
1185  
1186 /* save XPath context and XPathContextDATA for recursion */
1187 static xmlXPathContextPtr
1188 53 LibXML_save_context(xmlXPathContextPtr ctxt)
1189 {
1190 xmlXPathContextPtr copy;
1191 53 copy = xmlMalloc(sizeof(xmlXPathContext));
1192 53 ▶ if (copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (copy) { 53 0 53
1193 /* backup ctxt */
1194 53 memcpy(copy, ctxt, sizeof(xmlXPathContext));
1195 /* clear namespaces so that they are not freed and overwritten
1196 by configure_namespaces */
1197 53 ctxt->namespaces = NULL;
1198 /* backup data */
1199 53 copy->user = xmlMalloc(sizeof(XPathContextData));
1200 53 ▶ if (XPathContextDATA(copy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(copy)) { 53 0 53
1201 53 memcpy(XPathContextDATA(copy), XPathContextDATA(ctxt),sizeof(XPathContextData));
1202 /* clear ctxt->pool, so that it is not used freed during re-entrance */
1203 53 XPathContextDATA(ctxt)->pool = NULL;
1204 }
1205 }
1206 53 return copy;
1207 }
1208  
1209 /* restore XPath context and XPathContextDATA from a saved copy */
1210 static void
1211 53 LibXML_restore_context(xmlXPathContextPtr ctxt, xmlXPathContextPtr copy)
1212 {
1213 dTHX;
1214 /* cleanup */
1215 53 ▶ if (XPathContextDATA(ctxt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)) { 53 0 53
1216 /* cleanup newly created pool */
1217 53 ▶ if (XPathContextDATA(ctxt)->pool != NULL &&
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->pool != NULL && 0 53 53
1218 0 ▶ SvOK(XPathContextDATA(ctxt)->pool)) {
Branch: 1 branch
BranchTrueFalseTotal
SvOK(XPathContextDATA(ctxt)->pool)) { 0 0 0
1219 0 SvREFCNT_dec((SV *)XPathContextDATA(ctxt)->pool);
1220 }
1221 }
1222 53 ▶ if (ctxt->namespaces) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->namespaces) { 0 53 53
1223 /* free namespaces allocated during recursion */
1224 0 xmlFree( ctxt->namespaces );
1225 }
1226  
1227 /* restore context */
1228 53 ▶ if (copy) {
Branch: 1 branch
BranchTrueFalseTotal
if (copy) { 53 0 53
1229 /* 1st restore our data */
1230 53 ▶ if (XPathContextDATA(copy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(copy)) { 53 0 53
1231 53 memcpy(XPathContextDATA(ctxt),XPathContextDATA(copy),sizeof(XPathContextData));
1232 53 xmlFree(XPathContextDATA(copy));
1233 53 copy->user = XPathContextDATA(ctxt);
1234 }
1235 /* now copy the rest */
1236 53 memcpy(ctxt, copy, sizeof(xmlXPathContext));
1237 53 xmlFree(copy);
1238 }
1239 53 }
1240  
1241  
1242 /* ****************************************************************
1243 * Variable Lookup
1244 * **************************************************************** */
1245 /* Much of the code is borrowed from Matt Sergeant's XML::LibXSLT */
1246 static xmlXPathObjectPtr
1247 21 LibXML_generic_variable_lookup(void* varLookupData,
1248 const xmlChar *name,
1249 const xmlChar *ns_uri)
1250 {
1251 xmlXPathObjectPtr ret;
1252 xmlXPathContextPtr ctxt;
1253 xmlXPathContextPtr copy;
1254 XPathContextDataPtr data;
1255 I32 count;
1256 dTHX;
1257 21 dSP;
1258  
1259 21 ctxt = (xmlXPathContextPtr) varLookupData;
1260 21 ▶ if ( ctxt == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) 0 21 21
1261 0 croak("XPathContext: missing xpath context");
1262 21 data = XPathContextDATA(ctxt);
1263 21 ▶ if ( data == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( data == NULL ) 0 21 21
1264 0 croak("XPathContext: missing xpath context private data");
1265 21 ▶ if ( data->varLookup == NULL || !SvROK(data->varLookup) ||
Branch: 2 branches
BranchTrueFalseTotal
if ( data->varLookup == NULL || !SvROK(data->varLookup) || 21 0 21
if ( data->varLookup == NULL || !SvROK(data->varLookup) || 21 0 21
1266 21 ▶ SvTYPE(SvRV(data->varLookup)) != SVt_PVCV )
Branch: 1 branch
BranchTrueFalseTotal
SvTYPE(SvRV(data->varLookup)) != SVt_PVCV ) 0 21 21
1267 0 croak("XPathContext: lost variable lookup function!");
1268  
1269 21 ENTER;
1270 21 SAVETMPS;
1271 21 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 21 21
1272  
1273 21 ▶ XPUSHs( (data->varData != NULL) ? data->varData : &PL_sv_undef );
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs( (data->varData != NULL) ? data->varData : &PL_sv_undef ); 0 21 21
XPUSHs( (data->varData != NULL) ? data->varData : &PL_sv_undef ); 20 1 21
1274 21 ▶ XPUSHs(sv_2mortal(C2Sv(name,NULL)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(name,NULL))); 0 21 21
1275 21 ▶ XPUSHs(sv_2mortal(C2Sv(ns_uri,NULL)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(ns_uri,NULL))); 0 21 21
1276  
1277 /* save context to allow recursive usage of XPathContext */
1278 21 copy = LibXML_save_context(ctxt);
1279  
1280 21 PUTBACK ;
1281 21 count = call_sv(data->varLookup, G_SCALAR|G_EVAL);
1282 21 SPAGAIN;
1283  
1284 /* restore the xpath context */
1285 21 LibXML_restore_context(ctxt, copy);
1286  
1287 21 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 21 0 21
if (SvTRUE(ERRSV)) { 0 21 21
1288 0 (void) POPs;
1289 0 croak_obj;
1290 }
1291 21 ▶ if (count != 1) croak("XPathContext: variable lookup function returned none or more than one argument!");
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) croak("XPathContext: variable lookup function returned none or more than one argument!"); 0 21 21
1292  
1293 21 ret = LibXML_perldata_to_LibXMLdata(NULL, POPs);
1294  
1295 21 PUTBACK;
1296 21 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 21 0 21
1297 21 LEAVE;
1298 21 return ret;
1299 }
1300  
1301 /* ****************************************************************
1302 * Generic Extension Function
1303 * **************************************************************** */
1304 /* Much of the code is borrowed from Matt Sergeant's XML::LibXSLT */
1305 static void
1306 32 LibXML_generic_extension_function(xmlXPathParserContextPtr ctxt, int nargs)
1307 {
1308 xmlXPathObjectPtr obj,ret;
1309 32 xmlNodeSetPtr nodelist = NULL;
1310 int count;
1311 SV * perl_dispatch;
1312 int i;
1313 STRLEN len;
1314 32 ProxyNodePtr owner = NULL;
1315 SV *key;
1316 char *strkey;
1317 const char *function, *uri;
1318 SV **perl_function;
1319 dTHX;
1320 32 dSP;
1321 SV * data;
1322 xmlXPathContextPtr copy;
1323  
1324 /* warn("entered LibXML_generic_extension_function for %s\n",ctxt->context->function); */
1325 32 data = (SV *) ctxt->context->funcLookupData;
1326 32 ▶ if (ctxt->context->funcLookupData == NULL || !SvROK(data) ||
Branch: 2 branches
BranchTrueFalseTotal
if (ctxt->context->funcLookupData == NULL || !SvROK(data) || 32 0 32
if (ctxt->context->funcLookupData == NULL || !SvROK(data) || 32 0 32
1327 32 ▶ SvTYPE(SvRV(data)) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
SvTYPE(SvRV(data)) != SVt_PVHV) { 0 32 32
1328 0 croak("XPathContext: lost function lookup data structure!");
1329 }
1330  
1331 32 function = (char*) ctxt->context->function;
1332 32 uri = (char*) ctxt->context->functionURI;
1333  
1334 32 key = newSVpvn("",0);
1335 32 ▶ if (uri && *uri) {
Branch: 2 branches
BranchTrueFalseTotal
if (uri && *uri) { 8 24 32
if (uri && *uri) { 8 0 8
1336 8 sv_catpv(key, "{");
1337 8 sv_catpv(key, (const char*)uri);
1338 8 sv_catpv(key, "}");
1339 }
1340 32 sv_catpv(key, (const char*)function);
1341 32 strkey = SvPV(key, len);
1342 perl_function =
1343 32 hv_fetch((HV*)SvRV(data), strkey, len, 0);
1344 32 ▶ if ( perl_function == NULL || !SvOK(*perl_function) ||
Branch: 2 branches
BranchTrueFalseTotal
if ( perl_function == NULL || !SvOK(*perl_function) || 32 0 32
if ( perl_function == NULL || !SvOK(*perl_function) || 32 0 32
1345 32 ▶ !(SvPOK(*perl_function) ||
Branch: 1 branch
BranchTrueFalseTotal
!(SvPOK(*perl_function) || 31 1 32
1346 31 ▶ (SvROK(*perl_function) &&
Branch: 1 branch
BranchTrueFalseTotal
(SvROK(*perl_function) && 31 0 31
1347 31 ▶ SvTYPE(SvRV(*perl_function)) == SVt_PVCV))) {
Branch: 1 branch
BranchTrueFalseTotal
SvTYPE(SvRV(*perl_function)) == SVt_PVCV))) { 0 31 31
1348 0 croak("XPathContext: lost perl extension function!");
1349 }
1350 32 SvREFCNT_dec(key);
1351  
1352 32 ENTER;
1353 32 SAVETMPS;
1354 32 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 32 32
1355  
1356 32 ▶ XPUSHs(*perl_function);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*perl_function); 0 32 32
1357  
1358 /* set up call to perl dispatcher function */
1359 55 ▶ for (i = 0; i < nargs; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nargs; i++) { 23 32 55
1360 23 obj = (xmlXPathObjectPtr)valuePop(ctxt);
1361 23 switch (obj->type) {
1362 11 case XPATH_XSLT_TREE:
1363 case XPATH_NODESET:
1364 11 nodelist = obj->nodesetval;
1365 11 ▶ if ( nodelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist ) { 11 0 11
1366 11 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0))); 0 11 11
1367 11 ▶ XPUSHs(sv_2mortal(newSViv(nodelist->nodeNr)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(nodelist->nodeNr))); 0 11 11
1368 11 ▶ if ( nodelist->nodeNr > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist->nodeNr > 0 ) { 10 1 11
1369 int j;
1370 10 const char * cls = "XML::LibXML::Node";
1371 xmlNodePtr tnode;
1372 SV * element;
1373 10 int l = nodelist->nodeNr;
1374  
1375 3033 ▶ for( j = 0 ; j < l; j++){
Branch: 1 branch
BranchTrueFalseTotal
for( j = 0 ; j < l; j++){ 3023 10 3033
1376 3023 tnode = nodelist->nodeTab[j];
1377 3023 ▶ if( tnode != NULL && tnode->doc != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if( tnode != NULL && tnode->doc != NULL) { 3023 0 3023
if( tnode != NULL && tnode->doc != NULL) { 3023 0 3023
1378 3023 ▶ owner = PmmOWNERPO(PmmNewNode(INT2PTR(xmlNodePtr,tnode->doc)));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(PmmNewNode(INT2PTR(xmlNodePtr,tnode->doc))); 3023 0 3023
owner = PmmOWNERPO(PmmNewNode(INT2PTR(xmlNodePtr,tnode->doc))); 0 3023 3023
1379 } else {
1380 0 owner = NULL;
1381 }
1382 3023 ▶ if (tnode->type == XML_NAMESPACE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->type == XML_NAMESPACE_DECL) { 0 3023 3023
1383 0 element = NEWSV(0,0);
1384 0 cls = PmmNodeTypeName( tnode );
1385 0 element = sv_setref_pv( element,
1386 (const char *)cls,
1387 (void *)xmlCopyNamespace((xmlNsPtr)tnode)
1388 );
1389 }
1390 else {
1391 3023 element = PmmNodeToSv(tnode, owner);
1392 }
1393 3023 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 3023 3023
1394 }
1395 }
1396 } else {
1397 /* PP: We can't simply leave out an empty nodelist as Matt does! */
1398 /* PP: The number of arguments must match! */
1399 0 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0))); 0 0 0
1400 0 ▶ XPUSHs(sv_2mortal(newSViv(0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(0))); 0 0 0
1401 }
1402 /* prevent libxml2 from freeing the actual nodes */
1403 11 ▶ if (obj->boolval) obj->boolval=0;
Branch: 1 branch
BranchTrueFalseTotal
if (obj->boolval) obj->boolval=0; 0 11 11
1404 11 break;
1405 0 case XPATH_BOOLEAN:
1406 0 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0))); 0 0 0
1407 0 ▶ XPUSHs(sv_2mortal(newSViv(obj->boolval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(obj->boolval))); 0 0 0
1408 0 break;
1409 4 case XPATH_NUMBER:
1410 4 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0))); 0 4 4
1411 4 ▶ XPUSHs(sv_2mortal(newSVnv(obj->floatval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVnv(obj->floatval))); 0 4 4
1412 4 break;
1413 8 case XPATH_STRING:
1414 8 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0))); 0 8 8
1415 8 ▶ XPUSHs(sv_2mortal(C2Sv(obj->stringval, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(obj->stringval, 0))); 0 8 8
1416 8 break;
1417 0 default:
1418 0 warn("Unknown XPath return type (%d) in call to {%s}%s - assuming string", obj->type, uri, function);
1419 0 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0))); 0 0 0
1420 0 ▶ XPUSHs(sv_2mortal(C2Sv(xmlXPathCastToString(obj), 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(xmlXPathCastToString(obj), 0))); 0 0 0
1421 }
1422 23 xmlXPathFreeObject(obj);
1423 }
1424  
1425 /* save context to allow recursive usage of XPathContext */
1426 32 copy = LibXML_save_context(ctxt->context);
1427  
1428 /* call perl dispatcher */
1429 32 PUTBACK;
1430 32 perl_dispatch = sv_2mortal(newSVpv("XML::LibXML::XPathContext::_perl_dispatcher",0));
1431 32 count = call_sv(perl_dispatch, G_SCALAR|G_EVAL);
1432 32 SPAGAIN;
1433  
1434 /* restore the xpath context */
1435 32 LibXML_restore_context(ctxt->context, copy);
1436  
1437 32 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 32 0 32
if (SvTRUE(ERRSV)) { 1 31 32
1438 1 (void) POPs;
1439 1 croak_obj;
1440 }
1441  
1442 31 ▶ if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned none or more than one argument!");
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) croak("XPathContext: perl-dispatcher in pm file returned none or more than one argument!"); 0 31 31
1443  
1444 31 ret = LibXML_perldata_to_LibXMLdata(ctxt, POPs);
1445  
1446 31 valuePush(ctxt, ret);
1447 31 PUTBACK;
1448 31 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 31 0 31
1449 31 LEAVE;
1450 31 }
1451  
1452 static void
1453 180 LibXML_configure_namespaces( xmlXPathContextPtr ctxt ) {
1454 180 xmlNodePtr node = ctxt->node;
1455  
1456 180 ▶ if (ctxt->namespaces != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->namespaces != NULL) { 28 152 180
1457 28 xmlFree( ctxt->namespaces );
1458 28 ctxt->namespaces = NULL;
1459 }
1460 180 ▶ if (node != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (node != NULL) { 168 12 180
1461 168 ▶ if (node->type == XML_DOCUMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_DOCUMENT_NODE) { 132 36 168
1462 132 ctxt->namespaces = xmlGetNsList( node->doc,
1463 132 xmlDocGetRootElement( node->doc ) );
1464 } else {
1465 36 ctxt->namespaces = xmlGetNsList(node->doc, node);
1466 }
1467 168 ctxt->nsNr = 0;
1468 168 ▶ if (ctxt->namespaces != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->namespaces != NULL) { 45 123 168
1469 45 int cur=0;
1470 xmlNsPtr ns;
1471 /* we now walk through the list and
1472 drop every ns that was declared via registration */
1473 173 ▶ while (ctxt->namespaces[cur] != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while (ctxt->namespaces[cur] != NULL) { 128 45 173
1474 128 ns = ctxt->namespaces[cur];
1475 233 if (ns->prefix==NULL ||
1476 105 xmlHashLookup(ctxt->nsHash, ns->prefix) != NULL) {
1477 /* drop it */
1478 35 ctxt->namespaces[cur]=NULL;
1479 } else {
1480 93 ▶ if (cur != ctxt->nsNr) {
Branch: 1 branch
BranchTrueFalseTotal
if (cur != ctxt->nsNr) { 10 83 93
1481 /* move the item to the new tail */
1482 10 ctxt->namespaces[ctxt->nsNr]=ns;
1483 10 ctxt->namespaces[cur]=NULL;
1484 }
1485 93 ctxt->nsNr++;
1486 }
1487 128 cur++;
1488 }
1489 }
1490 }
1491 180 }
1492  
1493 static void
1494 166 LibXML_configure_xpathcontext( xmlXPathContextPtr ctxt ) {
1495 166 xmlNodePtr node = PmmSvNode(XPathContextDATA(ctxt)->node);
1496  
1497 166 ▶ if (node != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (node != NULL) { 154 12 166
1498 154 ctxt->doc = node->doc;
1499 } else {
1500 12 ctxt->doc = NULL;
1501 }
1502 166 ctxt->node = node;
1503 166 LibXML_configure_namespaces(ctxt);
1504 166 }
1505  
1506 #ifdef HAVE_READER_SUPPORT
1507  
1508 static void
1509 62 LibXML_set_reader_preserve_flag( xmlTextReaderPtr reader ) {
1510 HV *hash;
1511 char key[32];
1512  
1513 62 hash = get_hv("XML::LibXML::Reader::_preserve_flag", 0);
1514 62 ▶ if (!hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hash) { 0 62 62
1515 0 return;
1516 }
1517  
1518 62 (void) snprintf(key, sizeof(key), "%p", reader);
1519 62 (void) hv_store(hash, key, strlen(key), newSV(0), 0);
1520 }
1521  
1522 static int
1523 31 LibXML_get_reader_preserve_flag( xmlTextReaderPtr reader ) {
1524 HV *hash;
1525 char key[32];
1526  
1527 31 hash = get_hv("XML::LibXML::Reader::_preserve_flag", 0);
1528 31 ▶ if (!hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hash) { 0 31 31
1529 0 return 0;
1530 }
1531  
1532 31 (void) snprintf(key, sizeof(key), "%p", reader);
1533 31 ▶ if ( hv_exists(hash, key, strlen(key)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hv_exists(hash, key, strlen(key)) ) { 10 21 31
1534 10 (void) hv_delete(hash, key, strlen(key), G_DISCARD);
1535 10 return 1;
1536 }
1537  
1538 21 return 0;
1539 }
1540  
1541 #endif /* HAVE_READER_SUPPORT */
1542  
1543 extern void boot_XML__LibXML__Devel(pTHX_ CV*);
1544  
1545 MODULE = XML::LibXML PACKAGE = XML::LibXML
1546  
1547 PROTOTYPES: DISABLE
1548  
1549 BOOT:
1550 /* Load Devel first, so debug_memory can
1551 be called before any allocation. */
1552  
1553 /* The ++ is a bit hacky, but boot_blahblah_Devel, being an
1554 * XSUB body, will try to pop once more the mark we have just
1555 * (implicitly) popped, this boot sector also being an XSUB body */
1556 69 PL_markstack_ptr++;
1557 69 boot_XML__LibXML__Devel(aTHX_ cv);
1558 69 LIBXML_TEST_VERSION
1559 69 xmlInitParser();
1560 69 PmmSAXInitialize(aTHX);
1561 #ifndef WITH_SERRORS
1562 xmlGetWarningsDefaultValue = 0;
1563 #endif
1564 #ifdef LIBXML_CATALOG_ENABLED
1565 /* xmlCatalogSetDebug(10); */
1566 69 xmlInitializeCatalog(); /* use catalog data */
1567 #endif
1568  
1569  
1570 void
1571 _CLONE( class )
1572 CODE:
1573 #ifdef XML_LIBXML_THREADS
1574 if( PmmUSEREGISTRY )
1575 PmmCloneProxyNodes();
1576 #endif
1577  
1578 int
1579 _leaked_nodes()
1580 CODE:
1581 1 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 1 1
1582 #ifdef XML_LIBXML_THREADS
1583 if( PmmUSEREGISTRY )
1584 RETVAL = PmmProxyNodeRegistrySize();
1585 #endif
1586 OUTPUT:
1587 RETVAL
1588  
1589 void
1590 _dump_registry()
1591 PPCODE:
1592 #ifdef XML_LIBXML_THREADS
1593 if( PmmUSEREGISTRY )
1594 PmmDumpRegistry(PmmREGISTRY);
1595 #endif
1596  
1597 const char *
1598 LIBXML_DOTTED_VERSION()
1599 CODE:
1600 1 RETVAL = LIBXML_DOTTED_VERSION;
1601 OUTPUT:
1602 RETVAL
1603  
1604  
1605 int
1606 LIBXML_VERSION()
1607 CODE:
1608 85 ▶ RETVAL = LIBXML_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = LIBXML_VERSION; 1 84 85
1609 OUTPUT:
1610 RETVAL
1611  
1612 int
1613 HAVE_STRUCT_ERRORS()
1614 CODE:
1615 #ifdef WITH_SERRORS
1616 2 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 2 2
1617 #else
1618 RETVAL = 0;
1619 #endif
1620 OUTPUT:
1621 RETVAL
1622  
1623 int
1624 HAVE_SCHEMAS()
1625 CODE:
1626 #ifdef HAVE_SCHEMAS
1627 1 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 1 1
1628 # if LIBXML_VERSION == 20904
1629 /* exists but broken https://github.com/shlomif/libxml2-2.9.4-reader-schema-regression */
1630 RETVAL = 0;
1631 # endif
1632 #else
1633 RETVAL = 0;
1634 #endif
1635 OUTPUT:
1636 RETVAL
1637  
1638 int
1639 HAVE_READER()
1640 CODE:
1641 #ifdef HAVE_READER_SUPPORT
1642 2 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 2 2
1643 #else
1644 RETVAL = 0;
1645 #endif
1646 OUTPUT:
1647 RETVAL
1648  
1649 int
1650 HAVE_THREAD_SUPPORT()
1651 CODE:
1652 #ifdef XML_LIBXML_THREADS
1653 RETVAL = (PmmUSEREGISTRY ? 1 : 0);
1654 #else
1655 0 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 0 0
1656 #endif
1657 OUTPUT:
1658 RETVAL
1659  
1660  
1661 const char *
1662 LIBXML_RUNTIME_VERSION()
1663 CODE:
1664 73 RETVAL = xmlParserVersion;
1665 OUTPUT:
1666 RETVAL
1667  
1668 void
1669 END()
1670 CODE:
1671 69 xmlCleanupParser();
1672  
1673 int
1674 INIT_THREAD_SUPPORT()
1675 CODE:
1676 #ifdef XML_LIBXML_THREADS
1677 SV *threads = get_sv("threads::threads", 0); /* no create */
1678 if( threads && SvOK(threads) && SvTRUE(threads) ) {
1679 PROXY_NODE_REGISTRY_MUTEX = get_sv("XML::LibXML::__PROXY_NODE_REGISTRY_MUTEX",0);
1680 RETVAL = 1;
1681 } else {
1682 croak("XML::LibXML ':threads_shared' can only be used after 'use threads'");
1683 }
1684 #else
1685 0 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 0 0
1686 #endif
1687 OUTPUT:
1688 RETVAL
1689  
1690 void
1691 DISABLE_THREAD_SUPPORT()
1692 CODE:
1693 #ifdef XML_LIBXML_THREADS
1694 PROXY_NODE_REGISTRY_MUTEX = NULL;
1695 #else
1696 0 croak("XML::LibXML compiled without threads!");
1697 #endif
1698  
1699 SV*
1700 _parse_string(self, string, dir = &PL_sv_undef)
1701 SV * self
1702 SV * string
1703 SV * dir
1704 PREINIT:
1705 323 char * directory = NULL;
1706 STRLEN len;
1707 const char * ptr;
1708 HV * real_obj;
1709 int well_formed;
1710 int valid;
1711 int validate;
1712 xmlDocPtr real_doc;
1713 323 int recover = 0;
1714 323 PREINIT_SAVED_ERROR
1715 INIT:
1716 323 ▶ if (SvPOK(dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(dir)) { 1 322 323
1717 1 directory = SvPV(dir, len);
1718 1 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 1 1
1719 0 directory = NULL;
1720 }
1721 }
1722 /* If string is a reference to a string - dereference it.
1723 * See: https://rt.cpan.org/Ticket/Display.html?id=64051 (broke it)
1724 * https://rt.cpan.org/Ticket/Display.html?id=77864 (fixed it) */
1725 323 ▶ if (SvROK(string) && !SvOBJECT(SvRV(string))) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(string) && !SvOBJECT(SvRV(string))) { 3 320 323
if (SvROK(string) && !SvOBJECT(SvRV(string))) { 2 1 3
1726 2 string = SvRV(string);
1727 }
1728 323 ptr = SvPV_const(string, len);
1729 323 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 323 323
1730 0 croak("Empty string\n");
1731 XSRETURN_UNDEF;
1732 }
1733 CODE:
1734 323 RETVAL = &PL_sv_undef;
1735 323 INIT_ERROR_HANDLER;
1736 {
1737 323 xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(ptr, len);
1738 323 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 323 323
1739 0 CLEANUP_ERROR_HANDLER;
1740 0 REPORT_ERROR(1);
1741 0 croak("Could not create memory parser context!\n");
1742 }
1743 xs_warn( "context created\n");
1744 323 real_obj = LibXML_init_parser(self, ctxt);
1745 323 recover = LibXML_get_recover(real_obj);
1746  
1747  
1748 323 ▶ if ( directory != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( directory != NULL ) { 1 322 323
1749 1 ctxt->directory = directory;
1750 }
1751 323 ctxt->_private = (void*)self;
1752  
1753 /* make libxml2-2.6 display line number on error */
1754 323 ▶ if ( ctxt->input != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->input != NULL ) { 323 0 323
1755 323 ▶ if (directory != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (directory != NULL) { 1 322 323
1756 1 ctxt->input->filename = (char *) xmlStrdup((const xmlChar *) directory);
1757 } else {
1758 322 ctxt->input->filename = (char *) xmlStrdup((const xmlChar *) "");
1759 }
1760 }
1761  
1762 xs_warn( "context initialized\n" );
1763  
1764 323 xmlParseDocument(ctxt);
1765 xs_warn( "document parsed \n");
1766  
1767 323 ctxt->directory = NULL;
1768 323 well_formed = ctxt->wellFormed;
1769 323 valid = ctxt->valid;
1770 323 validate = ctxt->validate;
1771 323 real_doc = ctxt->myDoc;
1772 323 ctxt->myDoc = NULL;
1773 323 xmlFreeParserCtxt(ctxt);
1774 }
1775 323 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 323 0 323
1776 323 ▶ if (real_doc->URL != NULL) { /* free "" assigned above */
Branch: 1 branch
BranchTrueFalseTotal
if (real_doc->URL != NULL) { /* free "" assigned above */ 323 0 323
1777 323 xmlFree((char*) real_doc->URL);
1778 323 real_doc->URL = NULL;
1779 }
1780  
1781 323 ▶ if ( directory == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( directory == NULL ) { 322 1 323
1782 322 SV * newURI = sv_2mortal(newSVpvf("unknown-%p", (void*)real_doc));
1783 322 real_doc->URL = xmlStrdup((const xmlChar*)SvPV_nolen(newURI));
1784 } else {
1785 1 real_doc->URL = xmlStrdup((const xmlChar*)directory);
1786 }
1787 323 ▶ if ( ! LibXML_will_die_ctx(saved_error, recover) &&
Branch: 2 branches
BranchTrueFalseTotal
if ( ! LibXML_will_die_ctx(saved_error, recover) && 246 77 323
if ( ! LibXML_will_die_ctx(saved_error, recover) && 245 1 246
1788 245 ▶ (recover || ( well_formed &&
Branch: 2 branches
BranchTrueFalseTotal
(recover || ( well_formed && 245 0 245
(recover || ( well_formed && 0 245 245
1789 ( !validate
1790 0 ▶ || ( valid || ( real_doc->intSubset == NULL
Branch: 2 branches
BranchTrueFalseTotal
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
1791 0 ▶ && real_doc->extSubset == NULL )))))) {
Branch: 1 branch
BranchTrueFalseTotal
&& real_doc->extSubset == NULL )))))) { 0 0 0
1792 246 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
1793 } else {
1794 77 xmlFreeDoc(real_doc);
1795 77 real_doc=NULL;
1796 }
1797 }
1798  
1799 323 LibXML_cleanup_parser();
1800 323 CLEANUP_ERROR_HANDLER;
1801 323 REPORT_ERROR(recover);
1802 OUTPUT:
1803 RETVAL
1804  
1805 int
1806 _parse_sax_string(self, string)
1807 SV * self
1808 SV * string
1809 PREINIT:
1810 STRLEN len;
1811 char * ptr;
1812 HV * real_obj;
1813 37 int recover = 0;
1814 37 PREINIT_SAVED_ERROR
1815 INIT:
1816 37 ptr = SvPV(string, len);
1817 37 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 37 37
1818 0 croak("Empty string\n");
1819 XSRETURN_UNDEF;
1820 }
1821 CODE:
1822 37 RETVAL = 0;
1823 37 INIT_ERROR_HANDLER;
1824  
1825 {
1826 37 xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
1827 37 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 37 37
1828 0 CLEANUP_ERROR_HANDLER;
1829 0 ▶ REPORT_ERROR(recover ? recover : 1);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR(recover ? recover : 1); 0 0 0
1830 0 croak("Could not create memory parser context!\n");
1831 }
1832 xs_warn( "context created\n");
1833 37 real_obj = LibXML_init_parser(self, ctxt);
1834 37 recover = LibXML_get_recover(real_obj);
1835  
1836 37 PmmSAXInitContext( ctxt, self, saved_error );
1837 xs_warn( "context initialized \n");
1838 {
1839 37 RETVAL = xmlParseDocument(ctxt);
1840 xs_warn( "document parsed \n");
1841 }
1842  
1843 36 PmmSAXCloseContext(ctxt);
1844 36 xmlFreeParserCtxt(ctxt);
1845 }
1846  
1847 36 LibXML_cleanup_parser();
1848 36 CLEANUP_ERROR_HANDLER;
1849 36 REPORT_ERROR(recover);
1850 OUTPUT:
1851 RETVAL
1852  
1853 SV*
1854 _parse_fh(self, fh, dir = &PL_sv_undef)
1855 SV * self
1856 SV * fh
1857 SV * dir
1858 PREINIT:
1859 STRLEN len;
1860 9 char * directory = NULL;
1861 HV * real_obj;
1862 int well_formed;
1863 int valid;
1864 int validate;
1865 xmlDocPtr real_doc;
1866 9 int recover = 0;
1867 9 PREINIT_SAVED_ERROR
1868 INIT:
1869 9 ▶ if (SvPOK(dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(dir)) { 0 9 9
1870 0 directory = SvPV(dir, len);
1871 0 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 0 0
1872 0 directory = NULL;
1873 }
1874 }
1875 CODE:
1876 9 RETVAL = &PL_sv_undef;
1877 9 INIT_ERROR_HANDLER;
1878  
1879 {
1880 int read_length;
1881 char buffer[1024];
1882 xmlParserCtxtPtr ctxt;
1883  
1884 9 read_length = LibXML_read_perl(fh, buffer, 4);
1885 8 ▶ if (read_length <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (read_length <= 0) { 0 8 8
1886 0 CLEANUP_ERROR_HANDLER;
1887 0 croak( "Empty Stream\n" );
1888 }
1889  
1890 8 ctxt = xmlCreatePushParserCtxt(NULL, NULL, buffer, read_length, NULL);
1891 8 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 8 8
1892 0 CLEANUP_ERROR_HANDLER;
1893 0 REPORT_ERROR(1);
1894 0 croak("Could not create xml push parser context!\n");
1895 }
1896 xs_warn( "context created\n");
1897 8 real_obj = LibXML_init_parser(self, ctxt);
1898 8 recover = LibXML_get_recover(real_obj);
1899 #if LIBXML_VERSION > 20600
1900 /* dictionaries not support yet */
1901 8 ctxt->dictNames = 0;
1902 #endif
1903 8 ▶ if ( directory != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( directory != NULL ) { 0 8 8
1904 0 ctxt->directory = directory;
1905 }
1906 8 ctxt->_private = (void*)self;
1907 xs_warn( "context initialized \n");
1908 {
1909 int ret;
1910 14 ▶ while ((read_length = LibXML_read_perl(fh, buffer, 1024))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((read_length = LibXML_read_perl(fh, buffer, 1024))) { 7 6 13
1911 7 ret = xmlParseChunk(ctxt, buffer, read_length, 0);
1912 7 ▶ if ( ret != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != 0 ) { 1 6 7
1913 1 break;
1914 }
1915 }
1916 7 ret = xmlParseChunk(ctxt, buffer, 0, 1);
1917 xs_warn( "document parsed \n");
1918 }
1919  
1920 7 ctxt->directory = NULL;
1921 7 well_formed = ctxt->wellFormed;
1922 7 valid = ctxt->valid;
1923 7 validate = ctxt->validate;
1924 7 real_doc = ctxt->myDoc;
1925 7 ctxt->myDoc = NULL;
1926 7 xmlFreeParserCtxt(ctxt);
1927 }
1928  
1929 7 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 7 0 7
1930  
1931 7 ▶ if ( directory == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( directory == NULL ) { 7 0 7
1932 7 SV * newURI = sv_2mortal(newSVpvf("unknown-%p", (void*)real_doc));
1933 7 real_doc->URL = xmlStrdup((const xmlChar*)SvPV_nolen(newURI));
1934 } else {
1935 0 real_doc->URL = xmlStrdup((const xmlChar*)directory);
1936 }
1937  
1938 7 ▶ if ( ! LibXML_will_die_ctx(saved_error, recover) &&
Branch: 2 branches
BranchTrueFalseTotal
if ( ! LibXML_will_die_ctx(saved_error, recover) && 6 1 7
if ( ! LibXML_will_die_ctx(saved_error, recover) && 6 0 6
1939 6 ▶ (recover || ( well_formed &&
Branch: 2 branches
BranchTrueFalseTotal
(recover || ( well_formed && 6 0 6
(recover || ( well_formed && 0 6 6
1940 ( !validate
1941 0 ▶ || ( valid || ( real_doc->intSubset == NULL
Branch: 2 branches
BranchTrueFalseTotal
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
1942 0 ▶ && real_doc->extSubset == NULL )))))) {
Branch: 1 branch
BranchTrueFalseTotal
&& real_doc->extSubset == NULL )))))) { 0 0 0
1943 6 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
1944 } else {
1945 1 xmlFreeDoc(real_doc);
1946 1 real_doc=NULL;
1947 }
1948 }
1949  
1950 7 LibXML_cleanup_parser();
1951 7 CLEANUP_ERROR_HANDLER;
1952 7 REPORT_ERROR(recover);
1953 OUTPUT:
1954 RETVAL
1955  
1956 void
1957 _parse_sax_fh(self, fh, dir = &PL_sv_undef)
1958 SV * self
1959 SV * fh
1960 SV * dir
1961 PREINIT:
1962 STRLEN len;
1963 0 char * directory = NULL;
1964 HV * real_obj;
1965 0 int recover = 0;
1966 0 PREINIT_SAVED_ERROR
1967 INIT:
1968 0 ▶ if (SvPOK(dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(dir)) { 0 0 0
1969 0 directory = SvPV(dir, len);
1970 0 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 0 0
1971 0 directory = NULL;
1972 }
1973 }
1974 CODE:
1975 0 INIT_ERROR_HANDLER;
1976 {
1977 int read_length;
1978 char buffer[1024];
1979 xmlSAXHandlerPtr sax;
1980 xmlParserCtxtPtr ctxt;
1981  
1982 0 read_length = LibXML_read_perl(fh, buffer, 4);
1983 0 ▶ if (read_length <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (read_length <= 0) { 0 0 0
1984 0 CLEANUP_ERROR_HANDLER;
1985 0 croak( "Empty Stream\n" );
1986 }
1987  
1988 0 sax = PSaxGetHandler();
1989 0 ctxt = xmlCreatePushParserCtxt(sax, NULL, buffer, read_length, NULL);
1990 0 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 0 0
1991 0 CLEANUP_ERROR_HANDLER;
1992 0 ▶ REPORT_ERROR(recover ? recover : 1);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR(recover ? recover : 1); 0 0 0
1993 0 croak("Could not create xml push parser context!\n");
1994 }
1995 xs_warn( "context created\n");
1996 0 real_obj = LibXML_init_parser(self, ctxt);
1997 0 recover = LibXML_get_recover(real_obj);
1998  
1999 0 ▶ if ( directory != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( directory != NULL ) { 0 0 0
2000 0 ctxt->directory = directory;
2001 }
2002 0 PmmSAXInitContext( ctxt, self, saved_error );
2003 xs_warn( "context initialized \n");
2004  
2005 {
2006 int ret;
2007 0 ▶ while ((read_length = LibXML_read_perl(fh, buffer, 1024))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((read_length = LibXML_read_perl(fh, buffer, 1024))) { 0 0 0
2008 0 ret = xmlParseChunk(ctxt, buffer, read_length, 0);
2009 0 ▶ if ( ret != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != 0 ) { 0 0 0
2010 0 break;
2011 }
2012 }
2013 0 ret = xmlParseChunk(ctxt, buffer, 0, 1);
2014 xs_warn( "document parsed \n");
2015 }
2016  
2017 0 ctxt->directory = NULL;
2018 0 xmlFree(ctxt->sax);
2019 0 ctxt->sax = NULL;
2020 0 xmlFree(sax);
2021 0 PmmSAXCloseContext(ctxt);
2022 0 xmlFreeParserCtxt(ctxt);
2023 }
2024 0 CLEANUP_ERROR_HANDLER;
2025 0 LibXML_cleanup_parser();
2026 0 REPORT_ERROR(recover);
2027  
2028 SV*
2029 _parse_file(self, filename_sv)
2030 SV * self
2031 SV * filename_sv
2032 PREINIT:
2033 STRLEN len;
2034 char * filename;
2035 HV * real_obj;
2036 int well_formed;
2037 int valid;
2038 int validate;
2039 xmlDocPtr real_doc;
2040 67 int recover = 0;
2041 67 PREINIT_SAVED_ERROR
2042 INIT:
2043 67 filename = SvPV(filename_sv, len);
2044 67 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 67 67
2045 0 croak("Empty filename\n");
2046 XSRETURN_UNDEF;
2047 }
2048 CODE:
2049 67 RETVAL = &PL_sv_undef;
2050 67 INIT_ERROR_HANDLER;
2051  
2052 {
2053 67 xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
2054 67 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 1 66 67
2055 1 CLEANUP_ERROR_HANDLER;
2056 1 REPORT_ERROR(1);
2057 1 croak("Could not create file parser context for file \"%s\": %s\n",
2058 filename, strerror(errno));
2059 }
2060 xs_warn( "context created\n");
2061 66 real_obj = LibXML_init_parser(self, ctxt);
2062 66 recover = LibXML_get_recover(real_obj);
2063  
2064 66 ctxt->_private = (void*)self;
2065  
2066 xs_warn( "context initialized\n" );
2067 66 xmlParseDocument(ctxt);
2068 xs_warn( "document parsed \n");
2069  
2070 66 well_formed = ctxt->wellFormed;
2071 66 valid = ctxt->valid;
2072 66 validate = ctxt->validate;
2073 66 real_doc = ctxt->myDoc;
2074 66 ctxt->myDoc = NULL;
2075 66 xmlFreeParserCtxt(ctxt);
2076 }
2077  
2078 66 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 66 0 66
2079 66 ▶ if ( ! LibXML_will_die_ctx(saved_error, recover) &&
Branch: 2 branches
BranchTrueFalseTotal
if ( ! LibXML_will_die_ctx(saved_error, recover) && 61 5 66
if ( ! LibXML_will_die_ctx(saved_error, recover) && 61 0 61
2080 61 ▶ (recover || ( well_formed &&
Branch: 2 branches
BranchTrueFalseTotal
(recover || ( well_formed && 61 0 61
(recover || ( well_formed && 0 61 61
2081 ( !validate
2082 0 ▶ || ( valid || ( real_doc->intSubset == NULL
Branch: 2 branches
BranchTrueFalseTotal
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
|| ( valid || ( real_doc->intSubset == NULL 0 0 0
2083 0 ▶ && real_doc->extSubset == NULL )))))) {
Branch: 1 branch
BranchTrueFalseTotal
&& real_doc->extSubset == NULL )))))) { 0 0 0
2084 61 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
2085 } else {
2086 5 xmlFreeDoc(real_doc);
2087 5 real_doc=NULL;
2088 }
2089 }
2090  
2091 66 LibXML_cleanup_parser();
2092 66 CLEANUP_ERROR_HANDLER;
2093 66 REPORT_ERROR(recover);
2094 OUTPUT:
2095 RETVAL
2096  
2097 void
2098 _parse_sax_file(self, filename_sv)
2099 SV * self
2100 SV * filename_sv
2101 PREINIT:
2102 STRLEN len;
2103 char * filename;
2104 HV * real_obj;
2105 1 int recover = 0;
2106 1 PREINIT_SAVED_ERROR
2107 INIT:
2108 1 filename = SvPV(filename_sv, len);
2109 1 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 1 1
2110 0 croak("Empty filename\n");
2111 XSRETURN_UNDEF;
2112 }
2113 CODE:
2114 1 INIT_ERROR_HANDLER;
2115  
2116 {
2117 1 xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
2118 1 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 1 1
2119 0 CLEANUP_ERROR_HANDLER;
2120 0 ▶ REPORT_ERROR(recover ? recover : 1);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR(recover ? recover : 1); 0 0 0
2121 0 croak("Could not create file parser context for file \"%s\": %s\n",
2122 filename, strerror(errno));
2123 }
2124 xs_warn( "context created\n");
2125 1 real_obj = LibXML_init_parser(self, ctxt);
2126 1 recover = LibXML_get_recover(real_obj);
2127  
2128 1 ctxt->sax = PSaxGetHandler();
2129 1 PmmSAXInitContext( ctxt, self, saved_error );
2130 xs_warn( "context initialized \n");
2131  
2132 {
2133 1 xmlParseDocument(ctxt);
2134 xs_warn( "document parsed \n");
2135 }
2136  
2137 1 PmmSAXCloseContext(ctxt);
2138 1 xmlFreeParserCtxt(ctxt);
2139 }
2140  
2141 1 LibXML_cleanup_parser();
2142 1 CLEANUP_ERROR_HANDLER;
2143 1 REPORT_ERROR(recover);
2144  
2145 SV*
2146 _parse_html_string(self, string, svURL, svEncoding, options = 0)
2147 SV * self
2148 SV * string
2149 SV * svURL
2150 SV * svEncoding
2151 int options
2152 PREINIT:
2153 STRLEN len;
2154 char * ptr;
2155 18 char* URL = NULL;
2156 18 const char * encoding = NULL;
2157 HV * real_obj;
2158 htmlDocPtr real_doc;
2159 18 int recover = 0;
2160 18 PREINIT_SAVED_ERROR
2161 INIT:
2162 /* If string is a reference to a string - dereference it.
2163 * See: https://rt.cpan.org/Ticket/Display.html?id=64051 (broke it)
2164 * https://rt.cpan.org/Ticket/Display.html?id=77864 (fixed it) */
2165 18 ▶ if (SvROK(string) && !SvOBJECT(SvRV(string))) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(string) && !SvOBJECT(SvRV(string))) { 1 17 18
if (SvROK(string) && !SvOBJECT(SvRV(string))) { 1 0 1
2166 1 string = SvRV(string);
2167 }
2168 18 ptr = SvPV(string, len);
2169 18 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 18 18
2170 0 croak("Empty string\n");
2171 XSRETURN_UNDEF;
2172 }
2173 18 ▶ if (SvOK(svURL))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svURL)) 2 16 18
2174 2 URL = SvPV_nolen( svURL );
2175 18 ▶ if (SvOK(svEncoding))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svEncoding)) 6 12 18
2176 6 encoding = SvPV_nolen( svEncoding );
2177 CODE:
2178 18 RETVAL = &PL_sv_undef;
2179 18 INIT_ERROR_HANDLER;
2180 18 real_obj = LibXML_init_parser(self,NULL);
2181 18 ▶ if (encoding == NULL && SvUTF8( string )) {
Branch: 2 branches
BranchTrueFalseTotal
if (encoding == NULL && SvUTF8( string )) { 12 6 18
if (encoding == NULL && SvUTF8( string )) { 4 8 12
2182 4 encoding = "UTF-8";
2183 }
2184 18 ▶ if (options & HTML_PARSE_RECOVER) {
Branch: 1 branch
BranchTrueFalseTotal
if (options & HTML_PARSE_RECOVER) { 14 4 18
2185 14 ▶ recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1);
Branch: 1 branch
BranchTrueFalseTotal
recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1); 6 8 14
2186 }
2187 #if LIBXML_VERSION >= 20627
2188 18 real_doc = htmlReadDoc((xmlChar*)ptr, URL, encoding, options);
2189 #else
2190 real_doc = htmlParseDoc((xmlChar*)ptr, encoding);
2191 if ( real_doc ) {
2192 if (real_doc->URL) xmlFree((xmlChar *)real_doc->URL);
2193 if (URL) {
2194 real_doc->URL = xmlStrdup((const xmlChar*) URL);
2195 }
2196 }
2197 #endif
2198 18 ▶ if ( real_doc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc ) { 18 0 18
2199 18 ▶ if (URL==NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (URL==NULL) { 16 2 18
2200 16 SV * newURI = sv_2mortal(newSVpvf("unknown-%p", (void*)real_doc));
2201 16 real_doc->URL = xmlStrdup((const xmlChar*)SvPV_nolen(newURI));
2202 }
2203 /* This HTML memory parser doesn't use a ctxt; there is no "well-formed"
2204 * distinction, and if it manages to parse the HTML, it returns non-null. */
2205 18 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
2206 }
2207  
2208 18 LibXML_cleanup_parser();
2209 18 CLEANUP_ERROR_HANDLER;
2210 18 REPORT_ERROR(recover);
2211 OUTPUT:
2212 RETVAL
2213  
2214  
2215 SV*
2216 _parse_html_file(self, filename_sv, svURL, svEncoding, options = 0)
2217 SV * self
2218 SV * filename_sv
2219 SV * svURL
2220 SV * svEncoding
2221 int options
2222 PREINIT:
2223 STRLEN len;
2224 char * filename;
2225 6 char * URL = NULL;
2226 6 char * encoding = NULL;
2227 HV * real_obj;
2228 htmlDocPtr real_doc;
2229 6 int recover = 0;
2230 6 PREINIT_SAVED_ERROR
2231 INIT:
2232 6 filename = SvPV(filename_sv, len);
2233 6 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 6 6
2234 0 croak("Empty filename\n");
2235 XSRETURN_UNDEF;
2236 }
2237 6 ▶ if (SvOK(svURL))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svURL)) 1 5 6
2238 1 URL = SvPV_nolen( svURL );
2239 6 ▶ if (SvOK(svEncoding))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svEncoding)) 2 4 6
2240 2 encoding = SvPV_nolen( svEncoding );
2241 CODE:
2242 6 RETVAL = &PL_sv_undef;
2243 6 INIT_ERROR_HANDLER;
2244 6 real_obj = LibXML_init_parser(self,NULL);
2245 6 ▶ if (options & HTML_PARSE_RECOVER) {
Branch: 1 branch
BranchTrueFalseTotal
if (options & HTML_PARSE_RECOVER) { 3 3 6
2246 3 ▶ recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1);
Branch: 1 branch
BranchTrueFalseTotal
recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1); 0 3 3
2247 }
2248 #if LIBXML_VERSION >= 20627
2249 6 real_doc = htmlReadFile((const char *)filename,
2250 encoding,
2251 options);
2252 #else
2253 real_doc = htmlParseFile((const char *)filename, encoding);
2254 #endif
2255 6 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 6 0 6
2256  
2257 /* This HTML file parser doesn't use a ctxt; there is no "well-formed"
2258 * distinction, and if it manages to parse the HTML, it returns non-null. */
2259 6 ▶ if (URL) {
Branch: 1 branch
BranchTrueFalseTotal
if (URL) { 1 5 6
2260 1 ▶ if (real_doc->URL) xmlFree((xmlChar*) real_doc->URL);
Branch: 1 branch
BranchTrueFalseTotal
if (real_doc->URL) xmlFree((xmlChar*) real_doc->URL); 1 0 1
2261 1 real_doc->URL = xmlStrdup((const xmlChar*) URL);
2262 }
2263 6 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
2264  
2265 }
2266 6 CLEANUP_ERROR_HANDLER;
2267 6 LibXML_cleanup_parser();
2268 6 REPORT_ERROR(recover);
2269 OUTPUT:
2270 RETVAL
2271  
2272 SV*
2273 _parse_html_fh(self, fh, svURL, svEncoding, options = 0)
2274 SV * self
2275 SV * fh
2276 SV * svURL
2277 SV * svEncoding
2278 int options
2279 PREINIT:
2280 HV * real_obj;
2281 htmlDocPtr real_doc;
2282 4 int recover = 0;
2283 4 char * URL = NULL;
2284 4 PREINIT_SAVED_ERROR
2285 #if LIBXML_VERSION >= 20627
2286 4 ▶ char * encoding = NULL;
Branch: 1 branch
BranchTrueFalseTotal
char * encoding = NULL; 0 4 4
2287 #else
2288 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
2289 #endif
2290 INIT:
2291 4 ▶ if (SvOK(svURL))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svURL)) 1 3 4
2292 1 URL = SvPV_nolen( svURL );
2293 #if LIBXML_VERSION >= 20627
2294 4 ▶ if (SvOK(svEncoding))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(svEncoding)) 2 2 4
2295 2 encoding = SvPV_nolen( svEncoding );
2296 #else
2297 if (SvOK(svEncoding))
2298 enc = xmlParseCharEncoding(SvPV_nolen( svEncoding ));
2299 #endif
2300 CODE:
2301 4 RETVAL = &PL_sv_undef;
2302 4 INIT_ERROR_HANDLER;
2303 4 real_obj = LibXML_init_parser(self,NULL);
2304 4 ▶ if (options & HTML_PARSE_RECOVER) {
Branch: 1 branch
BranchTrueFalseTotal
if (options & HTML_PARSE_RECOVER) { 3 1 4
2305 3 ▶ recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1);
Branch: 1 branch
BranchTrueFalseTotal
recover = ((options & HTML_PARSE_NOERROR) ? 2 : 1); 0 3 3
2306 }
2307 #if LIBXML_VERSION >= 20627
2308  
2309 4 real_doc = htmlReadIO((xmlInputReadCallback) LibXML_read_perl,
2310 NULL,
2311 (void *) fh,
2312 URL,
2313 encoding,
2314 options);
2315 #else /* LIBXML_VERSION >= 20627 */
2316 {
2317 int read_length;
2318 int well_formed;
2319 char buffer[1024];
2320 htmlParserCtxtPtr ctxt;
2321  
2322 read_length = LibXML_read_perl(fh, buffer, 4);
2323 if (read_length <= 0) {
2324 CLEANUP_ERROR_HANDLER;
2325 croak( "Empty Stream\n" );
2326 }
2327 ctxt = htmlCreatePushParserCtxt(NULL, NULL, buffer, read_length,
2328 URL, enc);
2329 if (ctxt == NULL) {
2330 CLEANUP_ERROR_HANDLER;
2331 REPORT_ERROR(recover ? recover : 1);
2332 croak("Could not create html push parser context!\n");
2333 }
2334 ctxt->_private = (void*)self;
2335 {
2336 int ret;
2337 while ((read_length = LibXML_read_perl(fh, buffer, 1024))) {
2338 ret = htmlParseChunk(ctxt, buffer, read_length, 0);
2339 if ( ret != 0 ) {
2340 break;
2341 }
2342 }
2343 ret = htmlParseChunk(ctxt, buffer, 0, 1);
2344 }
2345 well_formed = ctxt->wellFormed;
2346 real_doc = ctxt->myDoc;
2347 ctxt->myDoc = NULL;
2348 htmlFreeParserCtxt(ctxt);
2349 }
2350 #endif /* LIBXML_VERSION >= 20627 */
2351 4 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 4 0 4
2352 4 ▶ if (real_doc->URL) xmlFree((xmlChar*) real_doc->URL);
Branch: 1 branch
BranchTrueFalseTotal
if (real_doc->URL) xmlFree((xmlChar*) real_doc->URL); 1 3 4
2353 4 ▶ if (URL) {
Branch: 1 branch
BranchTrueFalseTotal
if (URL) { 1 3 4
2354 1 real_doc->URL = xmlStrdup((const xmlChar*) URL);
2355 } else {
2356 3 SV * newURI = sv_2mortal(newSVpvf("unknown-%p", (void*)real_doc));
2357 3 real_doc->URL = xmlStrdup((const xmlChar*)SvPV_nolen(newURI));
2358 }
2359  
2360 4 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
2361 }
2362  
2363 4 LibXML_cleanup_parser();
2364 4 CLEANUP_ERROR_HANDLER;
2365 4 REPORT_ERROR(recover);
2366 OUTPUT:
2367 RETVAL
2368  
2369 SV*
2370 _parse_xml_chunk(self, svchunk, enc = &PL_sv_undef)
2371 SV * self
2372 SV * svchunk
2373 SV * enc
2374 PREINIT:
2375 STRLEN len;
2376 43 const char * encoding = "UTF-8";
2377 HV * real_obj;
2378 43 int recover = 0;
2379 xmlChar * chunk;
2380 43 xmlNodePtr rv = NULL;
2381 43 PREINIT_SAVED_ERROR
2382 INIT:
2383 43 ▶ if (SvPOK(enc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(enc)) { 0 43 43
2384 0 encoding = SvPV(enc, len);
2385 0 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 0 0
2386 0 encoding = "UTF-8";
2387 }
2388 }
2389 CODE:
2390 43 RETVAL = &PL_sv_undef;
2391 43 INIT_ERROR_HANDLER;
2392 43 real_obj = LibXML_init_parser(self,NULL);
2393  
2394 43 chunk = Sv2C(svchunk, (const xmlChar*)encoding);
2395  
2396 43 ▶ if ( chunk != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( chunk != NULL ) { 43 0 43
2397 43 recover = LibXML_get_recover(real_obj);
2398  
2399 43 rv = domReadWellBalancedString( NULL, chunk, recover );
2400  
2401 43 ▶ if ( rv != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rv != NULL ) { 35 8 43
2402 35 xmlNodePtr fragment= NULL;
2403 35 xmlNodePtr rv_end = NULL;
2404  
2405 /* now we append the nodelist to a document
2406 fragment which is unbound to a Document!!!! */
2407  
2408 /* step 1: create the fragment */
2409 35 fragment = xmlNewDocFragment( NULL );
2410 35 RETVAL = LibXML_NodeToSv(real_obj, fragment);
2411  
2412 /* step 2: set the node list to the fragment */
2413 35 fragment->children = rv;
2414 35 rv_end = rv;
2415 60 ▶ while ( rv_end->next != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( rv_end->next != NULL ) { 25 35 60
2416 25 rv_end->parent = fragment;
2417 25 rv_end = rv_end->next;
2418 }
2419 /* the following line is important, otherwise we'll have
2420 occasional segmentation faults
2421 */
2422 35 rv_end->parent = fragment;
2423 35 fragment->last = rv_end;
2424 }
2425  
2426 /* free the chunk we created */
2427 43 xmlFree( chunk );
2428 }
2429  
2430 43 LibXML_cleanup_parser();
2431 43 CLEANUP_ERROR_HANDLER;
2432 43 REPORT_ERROR(recover);
2433  
2434 35 ▶ if (rv == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv == NULL) { 0 35 35
2435 0 croak("_parse_xml_chunk: chunk parsing failed\n");
2436 }
2437 OUTPUT:
2438 RETVAL
2439  
2440 void
2441 _parse_sax_xml_chunk(self, svchunk, enc = &PL_sv_undef)
2442 SV * self
2443 SV * svchunk
2444 SV * enc
2445 PREINIT:
2446 STRLEN len;
2447 char * ptr;
2448 29 const char * encoding = "UTF-8";
2449 HV * real_obj;
2450 29 int recover = 0;
2451 xmlChar * chunk;
2452 29 int retCode = -1;
2453 29 xmlNodePtr nodes = NULL;
2454 29 xmlSAXHandlerPtr handler = NULL;
2455 29 PREINIT_SAVED_ERROR
2456 INIT:
2457 29 ▶ if (SvPOK(enc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(enc)) { 0 29 29
2458 0 encoding = SvPV(enc, len);
2459 0 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 0 0
2460 0 encoding = "UTF-8";
2461 }
2462 }
2463 29 ptr = SvPV(svchunk, len);
2464 29 ▶ if (len <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len <= 0) { 0 29 29
2465 0 croak("Empty string\n");
2466 }
2467 CODE:
2468 29 INIT_ERROR_HANDLER;
2469  
2470 29 chunk = Sv2C(svchunk, (const xmlChar*)encoding);
2471  
2472 29 ▶ if ( chunk != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( chunk != NULL ) { 29 0 29
2473 29 xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
2474 29 ▶ if (ctxt == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) { 0 29 29
2475 0 CLEANUP_ERROR_HANDLER;
2476 0 ▶ REPORT_ERROR(recover ? recover : 1);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR(recover ? recover : 1); 0 0 0
2477 0 croak("Could not create memory parser context!\n");
2478 }
2479 xs_warn( "context created\n");
2480 29 real_obj = LibXML_init_parser(self,ctxt);
2481 29 recover = LibXML_get_recover(real_obj);
2482  
2483 29 PmmSAXInitContext( ctxt, self, saved_error );
2484 29 handler = PSaxGetHandler();
2485  
2486 29 retCode = xmlParseBalancedChunkMemory( NULL,
2487 handler,
2488 ctxt,
2489 0,
2490 chunk,
2491 &nodes );
2492  
2493 29 xmlFree( handler );
2494 29 PmmSAXCloseContext(ctxt);
2495 29 xmlFreeParserCtxt(ctxt);
2496  
2497 /* free the chunk we created */
2498 29 xmlFree( chunk );
2499 }
2500  
2501 29 LibXML_cleanup_parser();
2502 29 CLEANUP_ERROR_HANDLER;
2503 29 REPORT_ERROR(recover);
2504  
2505 29 ▶ if (retCode == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (retCode == -1) { 0 29 29
2506 0 croak("_parse_sax_xml_chunk: chunk parsing failed\n");
2507 }
2508  
2509 int
2510 _processXIncludes(self, doc, options=0)
2511 SV * self
2512 SV * doc
2513 int options
2514 PREINIT:
2515 xmlDocPtr real_doc;
2516 HV * real_obj;
2517 22 int recover = 0;
2518 22 PREINIT_SAVED_ERROR
2519 INIT:
2520 22 real_doc = (xmlDocPtr) PmmSvNode(doc);
2521 22 ▶ if (real_doc == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (real_doc == NULL) { 2 20 22
2522 2 croak("No document to process!\n");
2523 XSRETURN_UNDEF;
2524 }
2525 CODE:
2526 20 RETVAL = 0;
2527 20 INIT_ERROR_HANDLER;
2528 20 real_obj = LibXML_init_parser(self,NULL);
2529 20 recover = LibXML_get_recover(real_obj);
2530  
2531 20 RETVAL = xmlXIncludeProcessFlags(real_doc,options);
2532  
2533 20 LibXML_cleanup_parser();
2534 20 CLEANUP_ERROR_HANDLER;
2535 20 REPORT_ERROR(recover);
2536  
2537 18 ▶ if ( RETVAL < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL < 0 ) { 0 18 18
2538 0 croak( "unknown error during XInclude processing\n" );
2539 XSRETURN_UNDEF;
2540 18 ▶ } else if ( RETVAL == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( RETVAL == 0 ) { 1 17 18
2541 1 RETVAL = 1;
2542 }
2543 OUTPUT:
2544 RETVAL
2545  
2546 SV*
2547 _start_push(self, with_sax=0)
2548 SV * self
2549 int with_sax
2550 PREINIT:
2551 HV * real_obj;
2552 78 int recover = 0;
2553 78 xmlParserCtxtPtr ctxt = NULL;
2554 78 PREINIT_SAVED_ERROR
2555 CODE:
2556 78 RETVAL = &PL_sv_undef;
2557 78 INIT_ERROR_HANDLER;
2558  
2559 /* create empty context */
2560 78 ctxt = xmlCreatePushParserCtxt( NULL, NULL, NULL, 0, NULL );
2561 78 real_obj = LibXML_init_parser(self,ctxt);
2562 78 recover = LibXML_get_recover(real_obj);
2563 78 ▶ if ( with_sax == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( with_sax == 1 ) { 36 42 78
2564 36 PmmSAXInitContext( ctxt, self, saved_error );
2565 }
2566  
2567 78 RETVAL = PmmContextSv( ctxt );
2568  
2569 78 LibXML_cleanup_parser();
2570 78 CLEANUP_ERROR_HANDLER;
2571 78 REPORT_ERROR(recover);
2572 OUTPUT:
2573 RETVAL
2574  
2575 int
2576 _push(self, pctxt, data)
2577 SV * self
2578 SV * pctxt
2579 SV * data
2580 PREINIT:
2581 HV * real_obj;
2582 302 int recover = 0;
2583 302 xmlParserCtxtPtr ctxt = NULL;
2584 302 STRLEN len = 0;
2585 302 char * chunk = NULL;
2586 302 PREINIT_SAVED_ERROR
2587 INIT:
2588 302 ctxt = PmmSvContext( pctxt );
2589 302 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 302 302
2590 0 croak( "parser context already freed\n" );
2591 0 XSRETURN_UNDEF;
2592 }
2593 302 ▶ if ( data == &PL_sv_undef ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( data == &PL_sv_undef ) { 0 302 302
2594 0 XSRETURN_UNDEF;
2595 }
2596 302 chunk = SvPV( data, len );
2597 302 ▶ if ( len <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( len <= 0 ) { 0 302 302
2598 xs_warn( "empty string" );
2599 0 XSRETURN_UNDEF;
2600 }
2601 CODE:
2602 302 RETVAL = 0;
2603 302 INIT_ERROR_HANDLER;
2604 302 real_obj = LibXML_init_parser(self,NULL);
2605 302 recover = LibXML_get_recover(real_obj);
2606  
2607 302 xmlParseChunk(ctxt, (const char *)chunk, len, 0);
2608  
2609 302 LibXML_cleanup_parser();
2610 302 CLEANUP_ERROR_HANDLER;
2611 302 REPORT_ERROR(recover);
2612  
2613 301 ▶ if ( ctxt->wellFormed == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->wellFormed == 0 ) { 6 295 301
2614 6 croak( "XML not well-formed in xmlParseChunk\n" );
2615 XSRETURN_UNDEF;
2616 }
2617 295 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 293 2 295
2618 OUTPUT:
2619 RETVAL
2620  
2621 SV*
2622 _end_push(self, pctxt, restore)
2623 SV * self
2624 SV * pctxt
2625 int restore
2626 PREINIT:
2627 HV * real_obj;
2628 int well_formed;
2629 41 xmlParserCtxtPtr ctxt = NULL;
2630 41 xmlDocPtr real_doc = NULL;
2631 41 PREINIT_SAVED_ERROR
2632 INIT:
2633 41 ctxt = PmmSvContext( pctxt );
2634 41 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 41 41
2635 0 croak( "parser context already freed\n" );
2636 XSRETURN_UNDEF;
2637 }
2638 CODE:
2639 41 RETVAL = &PL_sv_undef;
2640 41 INIT_ERROR_HANDLER;
2641 41 real_obj = LibXML_init_parser(self,NULL);
2642  
2643 41 xmlParseChunk(ctxt, "", 0, 1); /* finish the parse */
2644 xs_warn( "Finished with push parser\n" );
2645  
2646 41 well_formed = ctxt->wellFormed;
2647 41 real_doc = ctxt->myDoc;
2648 41 ctxt->myDoc = NULL;
2649 41 xmlFreeParserCtxt(ctxt);
2650 41 PmmNODE( SvPROXYNODE( pctxt ) ) = NULL;
2651  
2652 41 ▶ if ( real_doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc != NULL ) { 41 0 41
2653 41 ▶ if ( restore || well_formed ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( restore || well_formed ) { 40 1 41
if ( restore || well_formed ) { 38 2 40
2654 39 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
2655 } else {
2656 2 xmlFreeDoc(real_doc);
2657 2 real_doc = NULL;
2658 }
2659 }
2660  
2661 41 LibXML_cleanup_parser();
2662 41 CLEANUP_ERROR_HANDLER;
2663 41 REPORT_ERROR(restore);
2664  
2665 39 ▶ if ( real_doc == NULL ){
Branch: 1 branch
BranchTrueFalseTotal
if ( real_doc == NULL ){ 0 39 39
2666 0 croak( "no document found!\n" );
2667 XSRETURN_UNDEF;
2668 }
2669 OUTPUT:
2670 RETVAL
2671  
2672 void
2673 _end_sax_push(self, pctxt)
2674 SV * self
2675 SV * pctxt
2676 PREINIT:
2677 HV * real_obj;
2678 36 xmlParserCtxtPtr ctxt = NULL;
2679 36 PREINIT_SAVED_ERROR
2680 INIT:
2681 36 ctxt = PmmSvContext( pctxt );
2682 36 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 36 36
2683 0 croak( "parser context already freed\n" );
2684 }
2685 CODE:
2686 36 INIT_ERROR_HANDLER;
2687 36 real_obj = LibXML_init_parser(self,NULL);
2688  
2689 36 xmlParseChunk(ctxt, "", 0, 1); /* finish the parse */
2690 xs_warn( "Finished with SAX push parser\n" );
2691  
2692 36 xmlFree(ctxt->sax);
2693 36 ctxt->sax = NULL;
2694 36 PmmSAXCloseContext(ctxt);
2695 36 xmlFreeParserCtxt(ctxt);
2696 36 PmmNODE( SvPROXYNODE( pctxt ) ) = NULL;
2697  
2698 36 LibXML_cleanup_parser();
2699 36 CLEANUP_ERROR_HANDLER;
2700 36 REPORT_ERROR(0);
2701  
2702 SV*
2703 import_GDOME( CLASS, sv_gdome, deep=1 )
2704 SV * sv_gdome
2705 int deep
2706 PREINIT:
2707 0 ▶ xmlNodePtr node = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNodePtr node = NULL; 0 0 0
2708 INIT:
2709 0 RETVAL = &PL_sv_undef;
2710 #ifndef XML_LIBXML_GDOME_SUPPORT
2711 0 croak( "GDOME Support not compiled" );
2712 #endif
2713 if ( sv_gdome == NULL || sv_gdome == &PL_sv_undef ) {
2714 croak( "no XML::GDOME data found" );
2715 }
2716 #ifdef XML_LIBXML_GDOME_SUPPORT
2717 else {
2718 GdomeNode* gnode = NULL;
2719 gnode = (GdomeNode*)SvIV((SV*)SvRV( sv_gdome ));
2720 if ( gnode == NULL ) {
2721 croak( "no XML::GDOME data found (datastructure empty)" );
2722 }
2723  
2724 node = gdome_xml_n_get_xmlNode( gnode );
2725 if ( node == NULL ) {
2726 croak( "no XML::LibXML node found in GDOME object" );
2727 }
2728 }
2729 #endif
2730 CODE:
2731 if ( node->type == XML_NAMESPACE_DECL ) {
2732 const char * CLASS = "XML::LibXML::Namespace";
2733 RETVAL = NEWSV(0,0);
2734 RETVAL = sv_setref_pv( RETVAL,
2735 CLASS,
2736 (void*)xmlCopyNamespace((xmlNsPtr)node) );
2737 }
2738 else {
2739 RETVAL = PmmNodeToSv( PmmCloneNode( node, deep ), NULL );
2740 }
2741 OUTPUT:
2742 RETVAL
2743  
2744  
2745 SV*
2746 export_GDOME( CLASS, sv_libxml, deep=1 )
2747 SV * sv_libxml
2748 int deep
2749 PREINIT:
2750 0 ▶ xmlNodePtr node = NULL, retnode = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNodePtr node = NULL, retnode = NULL; 0 0 0
2751 INIT:
2752 0 RETVAL = &PL_sv_undef;
2753 #ifndef XML_LIBXML_GDOME_SUPPORT
2754 0 croak( "GDOME Support not configured!" );
2755 #endif
2756 if ( sv_libxml == NULL || sv_libxml == &PL_sv_undef ) {
2757 croak( "no XML::LibXML data found" );
2758 }
2759 node = PmmSvNode( sv_libxml );
2760 if ( node == NULL ) {
2761 croak( "no XML::LibXML data found (empty structure)" );
2762 }
2763 CODE:
2764 retnode = PmmCloneNode( node, deep );
2765 if ( retnode == NULL ) {
2766 croak( "Copy node failed" );
2767 }
2768  
2769 RETVAL = PmmNodeToGdomeSv( retnode );
2770 OUTPUT:
2771 RETVAL
2772  
2773  
2774 int
2775 load_catalog( self, filename )
2776 SV * filename
2777 PREINIT:
2778 1 const char * fn = (const char *) Sv2C(filename, NULL);
2779 INIT:
2780 1 ▶ if ( fn == NULL || xmlStrlen( (xmlChar *)fn ) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( fn == NULL || xmlStrlen( (xmlChar *)fn ) == 0 ) { 1 0 1
if ( fn == NULL || xmlStrlen( (xmlChar *)fn ) == 0 ) { 0 1 1
2781 0 croak( "cannot load catalog" );
2782 }
2783 CODE:
2784 #ifdef LIBXML_CATALOG_ENABLED
2785 1 RETVAL = xmlLoadCatalog( fn );
2786 #else
2787 XSRETURN_UNDEF;
2788 #endif
2789 OUTPUT:
2790 RETVAL
2791  
2792  
2793  
2794 int
2795 _default_catalog( self, catalog )
2796 SV * catalog
2797 PREINIT:
2798 #ifdef LIBXML_CATALOG_ENABLED
2799 0 ▶ xmlCatalogPtr catal = INT2PTR(xmlCatalogPtr,SvIV(SvRV(catalog)));
Branch: 1 branch
BranchTrueFalseTotal
xmlCatalogPtr catal = INT2PTR(xmlCatalogPtr,SvIV(SvRV(catalog))); 0 0 0
2800 #endif
2801 INIT:
2802 0 ▶ if ( catal == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( catal == NULL ) { 0 0 0
2803 0 croak( "empty catalog\n" );
2804 }
2805 CODE:
2806 0 warn( "this feature is not implemented" );
2807 0 ▶ RETVAL = 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 0; 0 0 0
2808 OUTPUT:
2809 RETVAL
2810  
2811 SV*
2812 _externalEntityLoader( loader )
2813 SV* loader
2814 CODE:
2815 {
2816 1 RETVAL = EXTERNAL_ENTITY_LOADER_FUNC;
2817 1 ▶ if(EXTERNAL_ENTITY_LOADER_FUNC == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(EXTERNAL_ENTITY_LOADER_FUNC == NULL) 1 0 1
2818 {
2819 1 EXTERNAL_ENTITY_LOADER_FUNC = newSVsv(loader);
2820 }
2821  
2822 1 ▶ if (LibXML_old_ext_ent_loader == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if (LibXML_old_ext_ent_loader == NULL ) 1 0 1
2823 {
2824 1 LibXML_old_ext_ent_loader = xmlGetExternalEntityLoader();
2825 1 xmlSetExternalEntityLoader((xmlExternalEntityLoader)LibXML_load_external_entity);
2826 }
2827 }
2828 OUTPUT:
2829 RETVAL
2830  
2831 MODULE = XML::LibXML PACKAGE = XML::LibXML::HashTable
2832  
2833 xmlHashTablePtr
2834 new(CLASS)
2835 const char * CLASS
2836 CODE:
2837 0 RETVAL = xmlHashCreate(8);
2838 OUTPUT:
2839 RETVAL
2840  
2841 void
2842 DESTROY( table )
2843 xmlHashTablePtr table
2844 CODE:
2845 xs_warn("DESTROY XMLHASHTABLE\n");
2846 0 PmmFreeHashTable(table);
2847  
2848 MODULE = XML::LibXML PACKAGE = XML::LibXML::ParserContext
2849  
2850 void
2851 DESTROY( self )
2852 SV * self
2853 CODE:
2854 xs_warn( "DROP PARSER CONTEXT!" );
2855 78 PmmContextREFCNT_dec( SvPROXYNODE( self ) );
2856  
2857  
2858 MODULE = XML::LibXML PACKAGE = XML::LibXML::Document
2859  
2860 SV *
2861 _toString(self, format=0)
2862 xmlDocPtr self
2863 int format
2864 PREINIT:
2865 30 xmlChar *result=NULL;
2866 30 int len=0;
2867 30 SV* internalFlag = NULL;
2868 30 int oldTagFlag = xmlSaveNoEmptyTags;
2869 30 xmlDtdPtr intSubset = NULL;
2870 /* PREINIT_SAVED_ERROR */
2871 CODE:
2872 30 RETVAL = &PL_sv_undef;
2873 30 internalFlag = get_sv("XML::LibXML::setTagCompression", 0);
2874 30 ▶ if( internalFlag ) {
Branch: 1 branch
BranchTrueFalseTotal
if( internalFlag ) { 30 0 30
2875 30 xmlSaveNoEmptyTags = SvTRUE(internalFlag);
2876 }
2877  
2878 30 internalFlag = get_sv("XML::LibXML::skipDTD", 0);
2879 30 ▶ if ( internalFlag && SvTRUE(internalFlag) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( internalFlag && SvTRUE(internalFlag) ) { 30 0 30
if ( internalFlag && SvTRUE(internalFlag) ) { 1 29 30
2880 1 intSubset = xmlGetIntSubset( self );
2881 1 ▶ if ( intSubset )
Branch: 1 branch
BranchTrueFalseTotal
if ( intSubset ) 1 0 1
2882 1 xmlUnlinkNode( INT2PTR(xmlNodePtr,intSubset) );
2883 }
2884  
2885 /* INIT_ERROR_HANDLER; */
2886  
2887 30 ▶ if ( format <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( format <= 0 ) { 29 1 30
2888 xs_warn( "use no formated toString!" );
2889 29 xmlDocDumpMemory(self, &result, &len);
2890 }
2891 else {
2892 1 int t_indent_var = xmlIndentTreeOutput;
2893 xs_warn( "use formated toString!" );
2894 1 xmlIndentTreeOutput = 1;
2895 1 xmlDocDumpFormatMemory( self, &result, &len, format );
2896 1 xmlIndentTreeOutput = t_indent_var;
2897 }
2898  
2899 30 ▶ if ( intSubset != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( intSubset != NULL ) { 1 29 30
2900 1 ▶ if (self->children == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->children == NULL) { 0 1 1
2901 0 xmlAddChild(INT2PTR(xmlNodePtr,self), INT2PTR(xmlNodePtr,intSubset));
2902 }
2903 else {
2904 1 xmlAddPrevSibling(self->children, INT2PTR(xmlNodePtr,intSubset));
2905 }
2906 }
2907  
2908 30 xmlSaveNoEmptyTags = oldTagFlag;
2909  
2910 /* REPORT_ERROR(0); */
2911  
2912 30 ▶ if (result == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (result == NULL) { 0 30 30
2913 xs_warn("Failed to convert doc to string");
2914 0 XSRETURN_UNDEF;
2915 } else {
2916 /* warn("%s, %d\n",result, len); */
2917 30 RETVAL = newSVpvn( (const char *)result, len );
2918 /* C2Sv( result, self->encoding ); */
2919 30 xmlFree(result);
2920 }
2921 OUTPUT:
2922 RETVAL
2923  
2924 int
2925 toFH( self, filehandler, format=0 )
2926 xmlDocPtr self
2927 SV * filehandler
2928 int format
2929 PREINIT:
2930 xmlOutputBufferPtr buffer;
2931 1 const xmlChar * encoding = NULL;
2932 1 xmlCharEncodingHandlerPtr handler = NULL;
2933 1 SV* internalFlag = NULL;
2934 1 int oldTagFlag = xmlSaveNoEmptyTags;
2935 1 xmlDtdPtr intSubset = NULL;
2936 1 int t_indent_var = xmlIndentTreeOutput;
2937 1 PREINIT_SAVED_ERROR
2938 CODE:
2939 1 internalFlag = get_sv("XML::LibXML::setTagCompression", 0);
2940 1 ▶ if( internalFlag ) {
Branch: 1 branch
BranchTrueFalseTotal
if( internalFlag ) { 1 0 1
2941 1 xmlSaveNoEmptyTags = SvTRUE(internalFlag);
2942 }
2943  
2944 1 internalFlag = get_sv("XML::LibXML::skipDTD", 0);
2945 1 ▶ if ( internalFlag && SvTRUE(internalFlag) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( internalFlag && SvTRUE(internalFlag) ) { 1 0 1
if ( internalFlag && SvTRUE(internalFlag) ) { 0 1 1
2946 0 intSubset = xmlGetIntSubset( self );
2947 0 ▶ if ( intSubset )
Branch: 1 branch
BranchTrueFalseTotal
if ( intSubset ) 0 0 0
2948 0 xmlUnlinkNode( INT2PTR(xmlNodePtr,intSubset) );
2949 }
2950  
2951 1 xmlRegisterDefaultOutputCallbacks();
2952 1 encoding = (self)->encoding;
2953 1 ▶ if ( encoding != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( encoding != NULL ) { 0 1 1
2954 0 ▶ if ( xmlParseCharEncoding((const char*)encoding) != XML_CHAR_ENCODING_UTF8) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlParseCharEncoding((const char*)encoding) != XML_CHAR_ENCODING_UTF8) { 0 0 0
2955 0 handler = xmlFindCharEncodingHandler((const char*)encoding);
2956 }
2957  
2958 }
2959 else {
2960 xs_warn("no encoding?");
2961 }
2962  
2963 1 buffer = xmlOutputBufferCreateIO( (xmlOutputWriteCallback) &LibXML_output_write_handler,
2964 (xmlOutputCloseCallback)&LibXML_output_close_handler,
2965 filehandler,
2966 handler );
2967  
2968 1 ▶ if ( format <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( format <= 0 ) { 1 0 1
2969 1 format = 0;
2970 1 xmlIndentTreeOutput = 0;
2971 }
2972 else {
2973 0 xmlIndentTreeOutput = 1;
2974 }
2975  
2976 1 INIT_ERROR_HANDLER;
2977  
2978 1 RETVAL = xmlSaveFormatFileTo( buffer,
2979 self,
2980 (const char *) encoding,
2981 format);
2982  
2983 1 ▶ if ( intSubset != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( intSubset != NULL ) { 0 1 1
2984 0 ▶ if (self->children == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->children == NULL) { 0 0 0
2985 0 xmlAddChild(INT2PTR(xmlNodePtr,self), INT2PTR(xmlNodePtr,intSubset));
2986 }
2987 else {
2988 0 xmlAddPrevSibling(self->children, INT2PTR(xmlNodePtr,intSubset));
2989 }
2990 }
2991  
2992 1 xmlIndentTreeOutput = t_indent_var;
2993 1 xmlSaveNoEmptyTags = oldTagFlag;
2994 1 CLEANUP_ERROR_HANDLER;
2995 1 REPORT_ERROR(0);
2996 OUTPUT:
2997 RETVAL
2998  
2999 int
3000 toFile( self, filename, format=0 )
3001 xmlDocPtr self
3002 char * filename
3003 int format
3004 PREINIT:
3005 1 SV* internalFlag = NULL;
3006 1 int oldTagFlag = xmlSaveNoEmptyTags;
3007 1 PREINIT_SAVED_ERROR
3008 CODE:
3009 1 internalFlag = get_sv("XML::LibXML::setTagCompression", 0);
3010 1 ▶ if( internalFlag ) {
Branch: 1 branch
BranchTrueFalseTotal
if( internalFlag ) { 1 0 1
3011 1 xmlSaveNoEmptyTags = SvTRUE(internalFlag);
3012 }
3013  
3014 1 INIT_ERROR_HANDLER;
3015  
3016 1 ▶ if ( format <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( format <= 0 ) { 1 0 1
3017 xs_warn( "use no formated toFile!" );
3018 1 RETVAL = xmlSaveFile( filename, self );
3019 }
3020 else {
3021 0 int t_indent_var = xmlIndentTreeOutput;
3022 0 xmlIndentTreeOutput = 1;
3023 0 RETVAL =xmlSaveFormatFile( filename,
3024 self,
3025 format);
3026 0 xmlIndentTreeOutput = t_indent_var;
3027 }
3028  
3029 1 xmlSaveNoEmptyTags = oldTagFlag;
3030 1 CLEANUP_ERROR_HANDLER;
3031 1 REPORT_ERROR(0);
3032  
3033 1 ▶ if ( RETVAL > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL > 0 ) 1 0 1
3034 1 RETVAL = 1;
3035 else
3036 0 XSRETURN_UNDEF;
3037 OUTPUT:
3038 RETVAL
3039  
3040 SV *
3041 toStringHTML(self)
3042 xmlDocPtr self
3043 ALIAS:
3044 XML::LibXML::Document::serialize_html = 1
3045 PREINIT:
3046 4 xmlChar *result=NULL;
3047 4 int len = 0;
3048 4 PREINIT_SAVED_ERROR
3049 CODE:
3050 PERL_UNUSED_VAR(ix);
3051 xs_warn( "use no formated toString!" );
3052 4 INIT_ERROR_HANDLER;
3053 4 htmlDocDumpMemory(self, &result, &len);
3054 4 CLEANUP_ERROR_HANDLER;
3055 4 REPORT_ERROR(0);
3056  
3057 4 ▶ if (result == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (result == NULL) { 0 4 4
3058 0 XSRETURN_UNDEF;
3059 } else {
3060 /* warn("%s, %d\n",result, len); */
3061 4 RETVAL = newSVpvn((char *)result, (STRLEN)len);
3062 4 xmlFree(result);
3063 }
3064 OUTPUT:
3065 RETVAL
3066  
3067  
3068 const char *
3069 URI( self )
3070 xmlDocPtr self
3071 ALIAS:
3072 XML::LibXML::Document::documentURI = 1
3073 CODE:
3074 PERL_UNUSED_VAR(ix);
3075 11 RETVAL = (const char*)xmlStrdup(self->URL );
3076 OUTPUT:
3077 RETVAL
3078  
3079 void
3080 setURI( self, new_URI )
3081 xmlDocPtr self
3082 char * new_URI
3083 CODE:
3084 2 ▶ if (new_URI) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_URI) { 2 0 2
3085 2 xmlFree((xmlChar*)self->URL );
3086 2 self->URL = xmlStrdup((const xmlChar*)new_URI);
3087 }
3088  
3089 SV*
3090 createDocument( CLASS, version="1.0", encoding=NULL )
3091 char * version
3092 char * encoding
3093 ALIAS:
3094 XML::LibXML::Document::new = 1
3095 PREINIT:
3096 121 ▶ xmlDocPtr doc=NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlDocPtr doc=NULL; 114 7 121
3097 CODE:
3098 PERL_UNUSED_VAR(ix);
3099 121 doc = xmlNewDoc((const xmlChar*)version);
3100 121 ▶ if (encoding && *encoding != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (encoding && *encoding != 0) { 6 115 121
if (encoding && *encoding != 0) { 6 0 6
3101 6 doc->encoding = (const xmlChar*)xmlStrdup((const xmlChar*)encoding);
3102 }
3103 121 RETVAL = PmmNodeToSv(INT2PTR(xmlNodePtr,doc),NULL);
3104 OUTPUT:
3105 RETVAL
3106  
3107 SV*
3108 createInternalSubset( self, Pname, extID, sysID )
3109 xmlDocPtr self
3110 SV * Pname
3111 SV * extID
3112 SV * sysID
3113 PREINIT:
3114 1 xmlDtdPtr dtd = NULL;
3115 1 xmlChar * name = NULL;
3116 1 xmlChar * externalID = NULL;
3117 1 xmlChar * systemID = NULL;
3118 CODE:
3119 1 name = Sv2C( Pname, NULL );
3120 1 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 1 1
3121 0 XSRETURN_UNDEF;
3122 }
3123  
3124 1 externalID = Sv2C(extID, NULL);
3125 1 systemID = Sv2C(sysID, NULL);
3126  
3127 1 dtd = xmlCreateIntSubset( self, name, externalID, systemID );
3128 1 xmlFree(externalID);
3129 1 xmlFree(systemID);
3130 1 xmlFree(name);
3131 1 ▶ if ( dtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd ) { 1 0 1
3132 1 RETVAL = PmmNodeToSv( INT2PTR(xmlNodePtr,dtd), PmmPROXYNODE(self) );
3133 }
3134 else {
3135 0 XSRETURN_UNDEF;
3136 }
3137 OUTPUT:
3138 RETVAL
3139  
3140 SV*
3141 createExternalSubset( self, Pname, extID, sysID )
3142 xmlDocPtr self
3143 SV * Pname
3144 SV * extID
3145 SV * sysID
3146 PREINIT:
3147 1 xmlDtdPtr dtd = NULL;
3148 1 xmlChar * name = NULL;
3149 1 xmlChar * externalID = NULL;
3150 1 xmlChar * systemID = NULL;
3151 CODE:
3152 1 name = Sv2C( Pname, NULL );
3153 1 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 1 1
3154 0 XSRETURN_UNDEF;
3155 }
3156  
3157 1 externalID = Sv2C(extID, NULL);
3158 1 systemID = Sv2C(sysID, NULL);
3159  
3160 1 dtd = xmlNewDtd( self, name, externalID, systemID );
3161  
3162 1 xmlFree(externalID);
3163 1 xmlFree(systemID);
3164 1 xmlFree(name);
3165 1 ▶ if ( dtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd ) { 1 0 1
3166 1 RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
3167 }
3168 else {
3169 0 XSRETURN_UNDEF;
3170 }
3171 OUTPUT:
3172 RETVAL
3173  
3174 SV*
3175 createDTD( self, Pname, extID, sysID )
3176 xmlDocPtr self
3177 SV * Pname
3178 SV * extID
3179 SV * sysID
3180 PREINIT:
3181 1 xmlDtdPtr dtd = NULL;
3182 1 xmlChar * name = NULL;
3183 1 xmlChar * externalID = NULL;
3184 1 xmlChar * systemID = NULL;
3185 CODE:
3186 1 name = Sv2C( Pname, NULL );
3187 1 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 1 1
3188 0 XSRETURN_UNDEF;
3189 }
3190  
3191 1 externalID = Sv2C(extID, NULL);
3192 1 systemID = Sv2C(sysID, NULL);
3193  
3194 1 dtd = xmlNewDtd( NULL, name, externalID, systemID );
3195 1 dtd->doc = self;
3196  
3197 1 xmlFree(externalID);
3198 1 xmlFree(systemID);
3199 1 xmlFree(name);
3200 1 ▶ if ( dtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd ) { 1 0 1
3201 1 RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
3202 }
3203 else {
3204 0 XSRETURN_UNDEF;
3205 }
3206 OUTPUT:
3207 RETVAL
3208  
3209 SV*
3210 createDocumentFragment( self )
3211 xmlDocPtr self
3212 CODE:
3213 3 RETVAL = PmmNodeToSv(xmlNewDocFragment(self), PmmPROXYNODE(self));
3214 OUTPUT:
3215 RETVAL
3216  
3217 SV*
3218 createElement( self, name )
3219 xmlDocPtr self
3220 SV* name
3221 PREINIT:
3222 xmlNodePtr newNode;
3223 69 xmlChar * elname = NULL;
3224 69 ProxyNodePtr docfrag = NULL;
3225 CODE:
3226 69 elname = nodeSv2C( name , (xmlNodePtr) self);
3227 69 ▶ if ( !LibXML_test_node_name( elname ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( elname ) ) { 5 64 69
3228 5 xmlFree( elname );
3229 5 croak( "bad name" );
3230 }
3231  
3232 64 newNode = xmlNewNode(NULL , elname);
3233 64 xmlFree(elname);
3234 64 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 64 0 64
3235 64 docfrag = PmmNewFragment( self );
3236 64 newNode->doc = self;
3237 64 xmlAddChild(PmmNODE(docfrag), newNode);
3238 64 RETVAL = PmmNodeToSv(newNode,docfrag);
3239 }
3240 else {
3241 xs_warn( "no node created!" );
3242 0 XSRETURN_UNDEF;
3243 }
3244 OUTPUT:
3245 RETVAL
3246  
3247 SV*
3248 createRawElement( self, name )
3249 xmlDocPtr self
3250 SV* name
3251 PREINIT:
3252 xmlNodePtr newNode;
3253 63 xmlChar * elname = NULL;
3254 63 ProxyNodePtr docfrag = NULL;
3255 CODE:
3256 63 elname = nodeSv2C( name , (xmlNodePtr) self);
3257 63 ▶ if ( !elname || xmlStrlen(elname) <= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !elname || xmlStrlen(elname) <= 0 ) { 63 0 63
if ( !elname || xmlStrlen(elname) <= 0 ) { 0 63 63
3258 0 xmlFree( elname );
3259 0 croak( "bad name" );
3260 }
3261  
3262 63 newNode = xmlNewDocNode(self,NULL , elname, NULL);
3263 63 xmlFree(elname);
3264 63 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 63 0 63
3265 63 docfrag = PmmNewFragment( self );
3266 63 xmlAddChild(PmmNODE(docfrag), newNode);
3267 63 RETVAL = PmmNodeToSv(newNode,docfrag);
3268 }
3269 else {
3270 xs_warn( "no node created!" );
3271 0 XSRETURN_UNDEF;
3272 }
3273 OUTPUT:
3274 RETVAL
3275  
3276 SV*
3277 createElementNS( self, nsURI, name )
3278 xmlDocPtr self
3279 SV * nsURI
3280 SV * name
3281 PREINIT:
3282 19 xmlChar * ename = NULL;
3283 19 xmlChar * prefix = NULL;
3284 19 xmlChar * localname = NULL;
3285 19 xmlChar * eURI = NULL;
3286 19 xmlNsPtr ns = NULL;
3287 19 ProxyNodePtr docfrag = NULL;
3288 19 xmlNodePtr newNode = NULL;
3289 CODE:
3290 19 ename = nodeSv2C( name , (xmlNodePtr) self );
3291 19 ▶ if ( !LibXML_test_node_name( ename ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( ename ) ) { 0 19 19
3292 0 xmlFree( ename );
3293 0 croak( "bad name" );
3294 }
3295  
3296 19 eURI = Sv2C( nsURI , NULL );
3297  
3298 19 ▶ if ( eURI != NULL && xmlStrlen(eURI)!=0 ){
Branch: 2 branches
BranchTrueFalseTotal
if ( eURI != NULL && xmlStrlen(eURI)!=0 ){ 19 0 19
if ( eURI != NULL && xmlStrlen(eURI)!=0 ){ 19 0 19
3299 19 localname = xmlSplitQName2(ename, &prefix);
3300 19 ▶ if ( localname == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname == NULL ) { 11 8 19
3301 11 localname = xmlStrdup( ename );
3302 }
3303  
3304 19 ns = xmlNewNs( NULL, eURI, prefix );
3305 19 newNode = xmlNewDocNode( self, ns, localname, NULL );
3306 19 newNode->nsDef = ns;
3307  
3308 19 xmlFree(localname);
3309 }
3310 else {
3311 xs_warn( " ordinary element " );
3312 /* ordinary element */
3313 0 localname = ename;
3314  
3315 0 newNode = xmlNewDocNode( self, NULL , localname, NULL );
3316 }
3317  
3318 19 docfrag = PmmNewFragment( self );
3319 19 xmlAddChild(PmmNODE(docfrag), newNode);
3320 19 RETVAL = PmmNodeToSv(newNode, docfrag);
3321  
3322 19 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 8 11 19
3323 8 xmlFree(prefix);
3324 }
3325 19 ▶ if ( eURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( eURI != NULL ) { 19 0 19
3326 19 xmlFree(eURI);
3327 }
3328 19 xmlFree(ename);
3329 OUTPUT:
3330 RETVAL
3331  
3332 SV*
3333 createRawElementNS( self, nsURI, name )
3334 xmlDocPtr self
3335 SV * nsURI
3336 SV * name
3337 PREINIT:
3338 8 xmlChar * ename = NULL;
3339 8 xmlChar * prefix = NULL;
3340 8 xmlChar * localname = NULL;
3341 8 xmlChar * eURI = NULL;
3342 8 xmlNsPtr ns = NULL;
3343 8 ProxyNodePtr docfrag = NULL;
3344 8 xmlNodePtr newNode = NULL;
3345 CODE:
3346 8 ename = nodeSv2C( name , (xmlNodePtr) self );
3347 8 ▶ if ( !LibXML_test_node_name( ename ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( ename ) ) { 0 8 8
3348 0 xmlFree( ename );
3349 0 croak( "bad name" );
3350 }
3351  
3352 8 eURI = Sv2C( nsURI , NULL );
3353  
3354 8 ▶ if ( eURI != NULL && xmlStrlen(eURI)!=0 ){
Branch: 2 branches
BranchTrueFalseTotal
if ( eURI != NULL && xmlStrlen(eURI)!=0 ){ 8 0 8
if ( eURI != NULL && xmlStrlen(eURI)!=0 ){ 8 0 8
3355 8 localname = xmlSplitQName2(ename, &prefix);
3356 8 ▶ if ( localname == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname == NULL ) { 1 7 8
3357 1 localname = xmlStrdup( ename );
3358 }
3359  
3360 8 newNode = xmlNewDocNode( self,NULL , localname, NULL );
3361  
3362 8 ns = xmlSearchNsByHref( self, newNode, eURI );
3363 8 ▶ if ( ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == NULL ) { 8 0 8
3364 /* create a new NS if the NS does not already exists */
3365 8 ns = xmlNewNs(newNode, eURI , prefix );
3366 }
3367  
3368 8 ▶ if ( ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == NULL ) { 0 8 8
3369 0 xmlFreeNode( newNode );
3370 0 xmlFree(eURI);
3371 0 xmlFree(localname);
3372 0 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 0 0 0
3373 0 xmlFree(prefix);
3374 }
3375 0 xmlFree(ename);
3376 0 XSRETURN_UNDEF;
3377 }
3378  
3379 8 xmlFree(localname);
3380 }
3381 else {
3382 xs_warn( " ordinary element " );
3383 /* ordinary element */
3384 0 localname = ename;
3385  
3386 0 newNode = xmlNewDocNode( self, NULL , localname, NULL );
3387 }
3388  
3389 8 xmlSetNs(newNode, ns);
3390 8 docfrag = PmmNewFragment( self );
3391 8 xmlAddChild(PmmNODE(docfrag), newNode);
3392 8 RETVAL = PmmNodeToSv(newNode, docfrag);
3393  
3394 8 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 7 1 8
3395 7 xmlFree(prefix);
3396 }
3397 8 ▶ if ( eURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( eURI != NULL ) { 8 0 8
3398 8 xmlFree(eURI);
3399 }
3400 8 xmlFree(ename);
3401 OUTPUT:
3402 RETVAL
3403  
3404 SV *
3405 createTextNode( self, content )
3406 xmlDocPtr self
3407 SV * content
3408 PREINIT:
3409 xmlNodePtr newNode;
3410 17 xmlChar * elname = NULL;
3411 17 ProxyNodePtr docfrag = NULL;
3412 CODE:
3413 17 elname = nodeSv2C( content , (xmlNodePtr) self );
3414 17 ▶ if ( elname != NULL || xmlStrlen(elname) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 17 17
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 0 0
3415 17 newNode = xmlNewDocText( self, elname );
3416 17 xmlFree(elname);
3417 17 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 17 0 17
3418 17 docfrag = PmmNewFragment( self );
3419 17 newNode->doc = self;
3420 17 xmlAddChild(PmmNODE(docfrag), newNode);
3421 17 RETVAL = PmmNodeToSv(newNode,docfrag);
3422 }
3423 else {
3424 xs_warn( "no node created!" );
3425 0 XSRETURN_UNDEF;
3426 }
3427 }
3428 else {
3429 0 XSRETURN_UNDEF;
3430 }
3431 OUTPUT:
3432 RETVAL
3433  
3434 SV *
3435 createComment( self , content )
3436 xmlDocPtr self
3437 SV * content
3438 PREINIT:
3439 xmlNodePtr newNode;
3440 6 xmlChar * elname = NULL;
3441 6 ProxyNodePtr docfrag = NULL;
3442 CODE:
3443 6 elname = nodeSv2C( content , (xmlNodePtr) self );
3444 6 ▶ if ( elname != NULL || xmlStrlen(elname) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 6 6
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 0 0
3445 6 newNode = xmlNewDocComment( self, elname );
3446 6 xmlFree(elname);
3447 6 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 6 0 6
3448 6 docfrag = PmmNewFragment( self );
3449 6 newNode->doc = self;
3450 6 xmlAddChild(PmmNODE(docfrag), newNode);
3451 xs_warn( newNode->name );
3452 6 RETVAL = PmmNodeToSv(newNode,docfrag);
3453 }
3454 else {
3455 xs_warn( "no node created!" );
3456 0 XSRETURN_UNDEF;
3457 }
3458 }
3459 else {
3460 0 XSRETURN_UNDEF;
3461 }
3462 OUTPUT:
3463 RETVAL
3464  
3465 SV *
3466 createCDATASection( self, content )
3467 xmlDocPtr self
3468 SV * content
3469 PREINIT:
3470 xmlNodePtr newNode;
3471 6 xmlChar * elname = NULL;
3472 6 ProxyNodePtr docfrag = NULL;
3473 CODE:
3474 6 elname = nodeSv2C( content , (xmlNodePtr)self );
3475 6 ▶ if ( elname != NULL || xmlStrlen(elname) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 6 6
if ( elname != NULL || xmlStrlen(elname) > 0 ) { 0 0 0
3476 6 newNode = xmlNewCDataBlock( self, elname, xmlStrlen(elname) );
3477 6 xmlFree(elname);
3478 6 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 6 0 6
3479 6 docfrag = PmmNewFragment( self );
3480 6 newNode->doc = self;
3481 6 xmlAddChild(PmmNODE(docfrag), newNode);
3482 xs_warn( "[CDATA section]" );
3483 6 RETVAL = PmmNodeToSv(newNode,docfrag);
3484 }
3485 else {
3486 xs_warn( "no node created!" );
3487 0 XSRETURN_UNDEF;
3488 }
3489 }
3490 else {
3491 0 XSRETURN_UNDEF;
3492 }
3493 OUTPUT:
3494 RETVAL
3495  
3496 SV*
3497 createEntityReference( self , pname )
3498 xmlDocPtr self
3499 SV * pname
3500 PREINIT:
3501 xmlNodePtr newNode;
3502 2 xmlChar * name = Sv2C( pname, NULL );
3503 2 ProxyNodePtr docfrag = NULL;
3504 CODE:
3505 2 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 2 2
3506 0 XSRETURN_UNDEF;
3507 }
3508 2 newNode = xmlNewReference( self, name );
3509 2 xmlFree(name);
3510 2 ▶ if ( newNode == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode == NULL ) { 0 2 2
3511 0 XSRETURN_UNDEF;
3512 }
3513 2 docfrag = PmmNewFragment( self );
3514 2 xmlAddChild(PmmNODE(docfrag), newNode);
3515 2 RETVAL = PmmNodeToSv( newNode, docfrag );
3516 OUTPUT:
3517 RETVAL
3518  
3519 SV*
3520 createAttribute( self, pname, pvalue=&PL_sv_undef )
3521 xmlDocPtr self
3522 SV * pname
3523 SV * pvalue
3524 PREINIT:
3525 11 xmlChar * name = NULL;
3526 11 xmlChar * value = NULL;
3527 11 xmlAttrPtr newAttr = NULL;
3528 11 xmlChar * buffer = NULL;
3529 CODE:
3530 11 name = nodeSv2C( pname , (xmlNodePtr) self );
3531 11 ▶ if ( !LibXML_test_node_name( name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( name ) ) { 5 6 11
3532 5 xmlFree(name);
3533 5 XSRETURN_UNDEF;
3534 }
3535  
3536 6 value = nodeSv2C( pvalue , (xmlNodePtr) self );
3537 /* unlike xmlSetProp, xmlNewDocProp does not encode entities in value */
3538 6 buffer = xmlEncodeEntitiesReentrant(self, value);
3539 6 newAttr = xmlNewDocProp( self, name, buffer );
3540 6 RETVAL = PmmNodeToSv((xmlNodePtr)newAttr, PmmPROXYNODE(self));
3541  
3542 6 xmlFree(name);
3543 6 xmlFree(buffer);
3544 6 ▶ if ( value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value ) { 6 0 6
3545 6 xmlFree(value);
3546 }
3547 OUTPUT:
3548 RETVAL
3549  
3550 SV*
3551 createAttributeNS( self, URI, pname, pvalue=&PL_sv_undef )
3552 xmlDocPtr self
3553 SV * URI
3554 SV * pname
3555 SV * pvalue
3556 PREINIT:
3557 16 xmlChar * name = NULL;
3558 16 xmlChar * value = NULL;
3559 16 xmlChar * prefix = NULL;
3560 16 const xmlChar * pchar = NULL;
3561 16 xmlChar * localname = NULL;
3562 16 xmlChar * nsURI = NULL;
3563 16 xmlAttrPtr newAttr = NULL;
3564 16 xmlNsPtr ns = NULL;
3565 CODE:
3566 16 name = nodeSv2C( pname , (xmlNodePtr) self );
3567 16 ▶ if ( !LibXML_test_node_name( name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( name ) ) { 5 11 16
3568 5 xmlFree(name);
3569 5 XSRETURN_UNDEF;
3570 }
3571  
3572 11 nsURI = Sv2C( URI , NULL );
3573 11 value = nodeSv2C( pvalue, (xmlNodePtr) self );
3574  
3575 19 ▶ if ( nsURI != NULL && xmlStrlen(nsURI) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI != NULL && xmlStrlen(nsURI) > 0 ) { 9 2 11
if ( nsURI != NULL && xmlStrlen(nsURI) > 0 ) { 9 0 9
3576 9 xmlNodePtr root = xmlDocGetRootElement(self );
3577 9 ▶ if ( root ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( root ) { 8 1 9
3578 8 pchar = xmlStrchr(name, ':');
3579 8 ▶ if ( pchar != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pchar != NULL ) { 8 0 8
3580 8 localname = xmlSplitQName2(name, &prefix);
3581 }
3582 else {
3583 0 localname = xmlStrdup( name );
3584 }
3585 8 ns = xmlSearchNsByHref( self, root, nsURI );
3586 8 ▶ if ( ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == NULL ) { 5 3 8
3587 /* create a new NS if the NS does not already exists */
3588 5 ns = xmlNewNs(root, nsURI , prefix );
3589 }
3590  
3591 8 ▶ if ( ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == NULL ) { 0 8 8
3592 0 xmlFree(nsURI);
3593 0 xmlFree(localname);
3594 0 ▶ if ( prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) { 0 0 0
3595 0 xmlFree(prefix);
3596 }
3597 0 xmlFree(name);
3598 0 ▶ if ( value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value ) { 0 0 0
3599 0 xmlFree(value);
3600 }
3601 0 XSRETURN_UNDEF;
3602 }
3603  
3604 8 newAttr = xmlNewDocProp( self, localname, value );
3605 8 xmlSetNs((xmlNodePtr)newAttr, ns);
3606  
3607 8 RETVAL = PmmNodeToSv((xmlNodePtr)newAttr, PmmPROXYNODE(self) );
3608  
3609 8 xmlFree(nsURI);
3610 8 xmlFree(name);
3611 8 ▶ if ( prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) { 8 0 8
3612 8 xmlFree(prefix);
3613 }
3614 8 xmlFree(localname);
3615 8 ▶ if ( value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value ) { 8 0 8
3616 8 xmlFree(value);
3617 }
3618 }
3619 else {
3620 1 croak( "can't create a new namespace on an attribute!" );
3621 xmlFree(name);
3622 if ( value ) {
3623 xmlFree(value);
3624 }
3625 XSRETURN_UNDEF;
3626 }
3627 }
3628 else {
3629 xmlChar *buffer;
3630 /* unlike xmlSetProp, xmlNewDocProp does not encode entities in value */
3631 2 buffer = xmlEncodeEntitiesReentrant(self, value);
3632 2 newAttr = xmlNewDocProp( self, name, buffer );
3633 2 RETVAL = PmmNodeToSv((xmlNodePtr)newAttr,PmmPROXYNODE(self));
3634 2 xmlFree(name);
3635 2 xmlFree(buffer);
3636 2 ▶ if ( value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value ) { 2 0 2
3637 2 xmlFree(value);
3638 }
3639 }
3640 OUTPUT:
3641 RETVAL
3642  
3643 SV*
3644 createProcessingInstruction(self, name, value=&PL_sv_undef)
3645 xmlDocPtr self
3646 SV * name
3647 SV * value
3648 ALIAS:
3649 createPI = 1
3650 PREINIT:
3651 4 xmlChar * n = NULL;
3652 4 xmlChar * v = NULL;
3653 4 xmlNodePtr newNode = NULL;
3654 4 ProxyNodePtr docfrag = NULL;
3655 CODE:
3656 PERL_UNUSED_VAR(ix);
3657 4 n = nodeSv2C(name, (xmlNodePtr)self);
3658 4 ▶ if ( !n ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !n ) { 0 4 4
3659 0 XSRETURN_UNDEF;
3660 }
3661 4 v = nodeSv2C(value, (xmlNodePtr)self);
3662 4 newNode = xmlNewPI(n,v);
3663 4 xmlFree(v);
3664 4 xmlFree(n);
3665 4 ▶ if ( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ) { 4 0 4
3666 4 docfrag = PmmNewFragment( self );
3667 4 newNode->doc = self;
3668 4 xmlAddChild(PmmNODE(docfrag), newNode);
3669 4 RETVAL = PmmNodeToSv(newNode,docfrag);
3670 } else {
3671 xs_warn( "no node created!" );
3672 0 XSRETURN_UNDEF;
3673 }
3674 OUTPUT:
3675 RETVAL
3676  
3677 void
3678 _setDocumentElement( self , proxy )
3679 xmlDocPtr self
3680 SV * proxy
3681 PREINIT:
3682 xmlNodePtr elem, oelem;
3683 INIT:
3684 96 elem = PmmSvNode(proxy);
3685 96 ▶ if ( elem == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( elem == NULL ) { 0 96 96
3686 0 XSRETURN_UNDEF;
3687 }
3688 CODE:
3689 /* please correct me if i am wrong: the document element HAS to be
3690 * an ELEMENT NODE
3691 */
3692 96 ▶ if ( elem->type == XML_ELEMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( elem->type == XML_ELEMENT_NODE ) { 96 0 96
3693 96 ▶ if ( self != elem->doc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self != elem->doc ) { 2 94 96
3694 2 domImportNode( self, elem, 1, 1 );
3695 }
3696  
3697 96 oelem = xmlDocGetRootElement( self );
3698 96 ▶ if ( oelem == NULL || oelem->_private == NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( oelem == NULL || oelem->_private == NULL ) { 0 96 96
if ( oelem == NULL || oelem->_private == NULL ) { 0 0 0
3699 96 xmlDocSetRootElement( self, elem );
3700 }
3701 else {
3702 0 ProxyNodePtr docfrag = PmmNewFragment( self );
3703 0 xmlReplaceNode( oelem, elem );
3704 0 xmlAddChild( PmmNODE(docfrag), oelem );
3705 0 PmmFixOwner( ((ProxyNodePtr)oelem->_private), docfrag);
3706 }
3707  
3708 96 ▶ if ( elem->_private != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( elem->_private != NULL ) { 96 0 96
3709 96 PmmFixOwner( SvPROXYNODE(proxy), PmmPROXYNODE(self));
3710 }
3711 } else {
3712 0 croak("setDocumentElement: ELEMENT node required");
3713 }
3714  
3715 SV *
3716 documentElement( self )
3717 xmlDocPtr self
3718 ALIAS:
3719 XML::LibXML::Document::getDocumentElement = 1
3720 PREINIT:
3721 xmlNodePtr elem;
3722 CODE:
3723 PERL_UNUSED_VAR(ix);
3724 253 elem = xmlDocGetRootElement( self );
3725 253 ▶ if ( elem ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( elem ) { 158 95 253
3726 158 RETVAL = PmmNodeToSv(elem, PmmPROXYNODE(self));
3727 }
3728 else {
3729 95 XSRETURN_UNDEF;
3730 }
3731 OUTPUT:
3732 RETVAL
3733  
3734 SV *
3735 externalSubset( self )
3736 xmlDocPtr self
3737 PREINIT:
3738 xmlDtdPtr dtd;
3739 CODE:
3740 10 ▶ if ( self->extSubset == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->extSubset == NULL ) { 8 2 10
3741 8 XSRETURN_UNDEF;
3742 }
3743  
3744 2 dtd = self->extSubset;
3745 2 RETVAL = PmmNodeToSv((xmlNodePtr)dtd, PmmPROXYNODE(self));
3746 OUTPUT:
3747 RETVAL
3748  
3749 SV *
3750 internalSubset( self )
3751 xmlDocPtr self
3752 PREINIT:
3753 xmlDtdPtr dtd;
3754 CODE:
3755 41 ▶ if ( self->intSubset == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->intSubset == NULL ) { 5 36 41
3756 5 XSRETURN_UNDEF;
3757 }
3758  
3759 36 dtd = self->intSubset;
3760 36 RETVAL = PmmNodeToSv(INT2PTR(xmlNodePtr,dtd), PmmPROXYNODE(self));
3761 OUTPUT:
3762 RETVAL
3763  
3764 void
3765 setExternalSubset( self, extdtd )
3766 xmlDocPtr self
3767 SV * extdtd
3768 PREINIT:
3769 2 xmlDtdPtr dtd = NULL;
3770 2 xmlDtdPtr olddtd = NULL;
3771 INIT:
3772 2 dtd = (xmlDtdPtr)PmmSvNode(extdtd);
3773 2 ▶ if ( dtd == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd == NULL ) { 0 2 2
3774 0 croak( "lost DTD node" );
3775 }
3776 CODE:
3777 2 ▶ if ( dtd && dtd != self->extSubset ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( dtd && dtd != self->extSubset ) { 2 0 2
if ( dtd && dtd != self->extSubset ) { 2 0 2
3778 2 ▶ if ( dtd->doc == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd->doc == NULL ) { 0 2 2
3779 0 xmlSetTreeDoc( (xmlNodePtr) dtd, self );
3780 2 ▶ } else if ( dtd->doc != self ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( dtd->doc != self ) { 0 2 2
3781 0 domImportNode( self, (xmlNodePtr) dtd,1,1);
3782 }
3783  
3784 2 ▶ if ( dtd == self->intSubset ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd == self->intSubset ) { 1 1 2
3785 1 xmlUnlinkNode( (xmlNodePtr)dtd );
3786 1 self->intSubset = NULL;
3787 }
3788  
3789 2 olddtd = self->extSubset;
3790 2 ▶ if ( olddtd && olddtd->_private == NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( olddtd && olddtd->_private == NULL ) { 0 2 2
if ( olddtd && olddtd->_private == NULL ) { 0 0 0
3791 0 xmlFreeDtd( olddtd );
3792 }
3793 2 self->extSubset = dtd;
3794 }
3795  
3796 void
3797 setInternalSubset( self, extdtd )
3798 xmlDocPtr self
3799 SV * extdtd
3800 PREINIT:
3801 2 xmlDtdPtr dtd = NULL;
3802 2 xmlDtdPtr olddtd = NULL;
3803 INIT:
3804 2 dtd = (xmlDtdPtr)PmmSvNode(extdtd);
3805 2 ▶ if ( dtd == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd == NULL ) { 0 2 2
3806 0 croak( "lost DTD node" );
3807 }
3808 CODE:
3809 2 ▶ if ( dtd && dtd != self->intSubset ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( dtd && dtd != self->intSubset ) { 2 0 2
if ( dtd && dtd != self->intSubset ) { 2 0 2
3810 2 ▶ if ( dtd->doc != self ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd->doc != self ) { 0 2 2
3811 0 croak( "can't import DTDs" );
3812 domImportNode( self, (xmlNodePtr) dtd,1,1);
3813 }
3814  
3815 2 ▶ if ( dtd == self->extSubset ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd == self->extSubset ) { 1 1 2
3816 1 self->extSubset = NULL;
3817 }
3818  
3819 2 olddtd = xmlGetIntSubset( self );
3820 2 ▶ if( olddtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if( olddtd ) { 1 1 2
3821 1 xmlReplaceNode( (xmlNodePtr)olddtd, (xmlNodePtr) dtd );
3822 1 ▶ if ( olddtd->_private == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( olddtd->_private == NULL ) { 0 1 1
3823 0 xmlFreeDtd( olddtd );
3824 }
3825 }
3826 else {
3827 1 ▶ if (self->children == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (self->children == NULL) 1 0 1
3828 1 xmlAddChild((xmlNodePtr) self, (xmlNodePtr) dtd);
3829 else
3830 0 xmlAddPrevSibling(self->children, (xmlNodePtr) dtd);
3831 }
3832 2 self->intSubset = dtd;
3833 }
3834  
3835 SV *
3836 removeInternalSubset( self )
3837 xmlDocPtr self
3838 PREINIT:
3839 1 xmlDtdPtr dtd = NULL;
3840 CODE:
3841 1 dtd = xmlGetIntSubset(self);
3842 1 ▶ if ( !dtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !dtd ) { 0 1 1
3843 0 XSRETURN_UNDEF;
3844 }
3845 1 xmlUnlinkNode( (xmlNodePtr)dtd );
3846 1 self->intSubset = NULL;
3847 1 RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
3848 OUTPUT:
3849 RETVAL
3850  
3851 SV *
3852 removeExternalSubset( self )
3853 xmlDocPtr self
3854 PREINIT:
3855 1 xmlDtdPtr dtd = NULL;
3856 CODE:
3857 1 dtd = self->extSubset;
3858 1 ▶ if ( !dtd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !dtd ) { 0 1 1
3859 0 XSRETURN_UNDEF;
3860 }
3861 1 self->extSubset = NULL;
3862 1 RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
3863 OUTPUT:
3864 RETVAL
3865  
3866 SV *
3867 importNode( self, node, dummy=0 )
3868 xmlDocPtr self
3869 xmlNodePtr node
3870 int dummy
3871 PREINIT:
3872 4 xmlNodePtr ret = NULL;
3873 4 ProxyNodePtr docfrag = NULL;
3874 CODE:
3875 4 ▶ if ( node->type == XML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( node->type == XML_DOCUMENT_NODE 4 0 4
3876 4 ▶ || node->type == XML_HTML_DOCUMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
|| node->type == XML_HTML_DOCUMENT_NODE ) { 0 4 4
3877 0 croak( "Can't import Documents!" );
3878 XSRETURN_UNDEF;
3879 }
3880 4 ▶ if (node->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_DTD_NODE) { 0 4 4
3881 0 croak("Can't import DTD nodes");
3882 }
3883  
3884 4 ret = domImportNode( self, node, 0, 1 );
3885 4 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 4 0 4
3886 4 docfrag = PmmNewFragment( self );
3887 4 xmlAddChild( PmmNODE(docfrag), ret );
3888 4 RETVAL = PmmNodeToSv( ret, docfrag);
3889 }
3890 else {
3891 0 XSRETURN_UNDEF;
3892 }
3893 OUTPUT:
3894 RETVAL
3895  
3896 SV *
3897 adoptNode( self, node )
3898 xmlDocPtr self
3899 xmlNodePtr node
3900 PREINIT:
3901 6 xmlNodePtr ret = NULL;
3902 6 ProxyNodePtr docfrag = NULL;
3903 CODE:
3904 6 ▶ if ( node->type == XML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( node->type == XML_DOCUMENT_NODE 6 0 6
3905 6 ▶ || node->type == XML_HTML_DOCUMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
|| node->type == XML_HTML_DOCUMENT_NODE ) { 0 6 6
3906 0 croak( "Can't adopt Documents!" );
3907 XSRETURN_UNDEF;
3908 }
3909 6 ▶ if (node->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_DTD_NODE) { 0 6 6
3910 0 croak("Can't adopt DTD nodes");
3911 }
3912  
3913 6 ret = domImportNode( self, node, 1, 1 );
3914  
3915 6 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 6 0 6
3916 6 docfrag = PmmNewFragment( self );
3917 6 RETVAL = PmmNodeToSv(node, docfrag);
3918 6 xmlAddChild( PmmNODE(docfrag), ret );
3919 6 PmmFixOwner(SvPROXYNODE(RETVAL), docfrag);
3920 }
3921 else {
3922 0 XSRETURN_UNDEF;
3923 }
3924 OUTPUT:
3925 RETVAL
3926  
3927 char*
3928 encoding( self )
3929 xmlDocPtr self
3930 ALIAS:
3931 XML::LibXML::Document::getEncoding = 1
3932 XML::LibXML::Document::xmlEncoding = 2
3933 CODE:
3934 PERL_UNUSED_VAR(ix);
3935 23 RETVAL = (char *) self->encoding;
3936 OUTPUT:
3937 RETVAL
3938  
3939 void
3940 setEncoding( self, encoding = NULL )
3941 xmlDocPtr self
3942 char *encoding
3943 PREINIT:
3944 7 int charset = XML_CHAR_ENCODING_ERROR;
3945 CODE:
3946 7 ▶ if ( self->encoding != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->encoding != NULL ) { 1 6 7
3947 1 xmlFree( (xmlChar*) self->encoding );
3948 }
3949 7 ▶ if (encoding!=NULL && strlen(encoding)) {
Branch: 2 branches
BranchTrueFalseTotal
if (encoding!=NULL && strlen(encoding)) { 6 1 7
if (encoding!=NULL && strlen(encoding)) { 6 0 6
3950 6 self->encoding = xmlStrdup( (const xmlChar *)encoding );
3951 6 charset = (int)xmlParseCharEncoding( (const char*)self->encoding );
3952 6 ▶ if ( charset <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( charset <= 0 ) { 0 6 6
3953 0 charset = XML_CHAR_ENCODING_ERROR;
3954 }
3955 } else {
3956 1 self->encoding=NULL;
3957 1 charset = XML_CHAR_ENCODING_UTF8;
3958 }
3959 7 SetPmmNodeEncoding(self, charset);
3960  
3961  
3962 int
3963 standalone( self )
3964 xmlDocPtr self
3965 ALIAS:
3966 XML::LibXML::Document::xmlStandalone = 1
3967 CODE:
3968 PERL_UNUSED_VAR(ix);
3969 3 ▶ RETVAL = self->standalone;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->standalone; 0 3 3
3970 OUTPUT:
3971 RETVAL
3972  
3973 void
3974 setStandalone( self, value = 0 )
3975 xmlDocPtr self
3976 int value
3977 CODE:
3978 1 ▶ if ( value > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value > 0 ) { 1 0 1
3979 1 self->standalone = 1;
3980 }
3981 0 ▶ else if ( value < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( value < 0 ) { 0 0 0
3982 0 self->standalone = -1;
3983 }
3984 else {
3985 0 self->standalone = 0;
3986 }
3987  
3988 char*
3989 version( self )
3990 xmlDocPtr self
3991 ALIAS:
3992 XML::LibXML::Document::getVersion = 1
3993 XML::LibXML::Document::xmlVersion = 2
3994 CODE:
3995 PERL_UNUSED_VAR(ix);
3996 15 RETVAL = (char *) self->version;
3997 OUTPUT:
3998 RETVAL
3999  
4000 void
4001 setVersion( self, version )
4002 xmlDocPtr self
4003 char *version
4004 CODE:
4005 71 ▶ if ( self->version != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->version != NULL ) { 71 0 71
4006 71 xmlFree( (xmlChar*) self->version );
4007 }
4008 71 self->version = xmlStrdup( (const xmlChar*)version );
4009  
4010 int
4011 compression( self )
4012 xmlDocPtr self
4013 CODE:
4014 1 RETVAL = xmlGetDocCompressMode(self);
4015 OUTPUT:
4016 RETVAL
4017  
4018 void
4019 setCompression( self, zLevel )
4020 xmlDocPtr self
4021 int zLevel
4022 CODE:
4023 0 xmlSetDocCompressMode(self, zLevel);
4024  
4025  
4026 int
4027 is_valid(self, ...)
4028 xmlDocPtr self
4029 PREINIT:
4030 xmlValidCtxt cvp;
4031 3 xmlDtdPtr dtd = NULL;
4032 SV * dtd_sv;
4033 3 PREINIT_SAVED_ERROR
4034 CODE:
4035 3 INIT_ERROR_HANDLER;
4036  
4037 3 memset(&cvp, 0, sizeof(cvp));
4038 3 cvp.userData = saved_error;
4039 3 cvp.error = (xmlValidityErrorFunc)LibXML_validity_error_ctx;
4040 3 cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning_ctx;
4041  
4042 3 ▶ PmmClearPSVI(self);
Branch: 4 branches
BranchTrueFalseTotal
PmmClearPSVI(self); 3 0 3
PmmClearPSVI(self); 3 0 3
PmmClearPSVI(self); 3 0 3
PmmClearPSVI(self); 1 2 3
4043 3 ▶ PmmInvalidatePSVI(self);
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI(self); 3 0 3
PmmInvalidatePSVI(self); 3 0 3
4044 3 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 2 1 3
4045 2 dtd_sv = ST(1);
4046 2 ▶ if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) { 2 0 2
if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) { 2 0 2
4047 2 dtd = (xmlDtdPtr)PmmSvNode(dtd_sv);
4048 }
4049 2 RETVAL = xmlValidateDtd(&cvp, self, dtd);
4050 }
4051 else {
4052 1 RETVAL = xmlValidateDocument(&cvp, self);
4053 }
4054 3 CLEANUP_ERROR_HANDLER;
4055 /* REPORT_ERROR(1); */
4056 OUTPUT:
4057 RETVAL
4058  
4059 int
4060 validate(self, ...)
4061 xmlDocPtr self
4062 PREINIT:
4063 xmlValidCtxt cvp;
4064 xmlDtdPtr dtd;
4065 SV * dtd_sv;
4066 5 PREINIT_SAVED_ERROR
4067 CODE:
4068 5 INIT_ERROR_HANDLER;
4069  
4070 5 memset(&cvp, 0, sizeof(cvp));
4071 5 cvp.userData = saved_error;
4072 5 cvp.error = (xmlValidityErrorFunc)LibXML_validity_error_ctx;
4073 5 cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning_ctx;
4074  
4075 5 ▶ PmmClearPSVI(self);
Branch: 4 branches
BranchTrueFalseTotal
PmmClearPSVI(self); 5 0 5
PmmClearPSVI(self); 5 0 5
PmmClearPSVI(self); 5 0 5
PmmClearPSVI(self); 3 2 5
4076 5 ▶ PmmInvalidatePSVI(self);
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI(self); 5 0 5
PmmInvalidatePSVI(self); 5 0 5
4077  
4078 5 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 2 3 5
4079 2 dtd_sv = ST(1);
4080 2 ▶ if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) { 2 0 2
if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) { 2 0 2
4081 2 dtd = (xmlDtdPtr)PmmSvNode(dtd_sv);
4082 }
4083 else {
4084 0 CLEANUP_ERROR_HANDLER;
4085 0 croak("is_valid: argument must be a DTD object");
4086 }
4087 2 RETVAL = xmlValidateDtd(&cvp, self , dtd);
4088 }
4089 else {
4090 3 RETVAL = xmlValidateDocument(&cvp, self);
4091 }
4092 5 CLEANUP_ERROR_HANDLER;
4093 5 REPORT_ERROR(RETVAL ? 1 : 0);
4094 OUTPUT:
4095 RETVAL
4096  
4097 SV*
4098 cloneNode( self, deep=0 )
4099 xmlDocPtr self
4100 int deep
4101 PREINIT:
4102 2 xmlDocPtr ret = NULL;
4103 CODE:
4104 2 ret = xmlCopyDoc( self, deep );
4105 2 ▶ if ( ret == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret == NULL ) { 0 2 2
4106 0 XSRETURN_UNDEF;
4107 }
4108 2 RETVAL = PmmNodeToSv((xmlNodePtr)ret, NULL);
4109 OUTPUT:
4110 RETVAL
4111  
4112 SV*
4113 getElementById( self, id )
4114 xmlDocPtr self
4115 const char * id
4116 ALIAS:
4117 XML::LibXML::Document::getElementsById = 1
4118 PREINIT:
4119 xmlNodePtr elem;
4120 xmlAttrPtr attr;
4121 CODE:
4122 PERL_UNUSED_VAR(ix);
4123 22 ▶ if ( id != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( id != NULL ) { 22 0 22
4124 22 attr = xmlGetID(self, (xmlChar *) id);
4125 22 ▶ if (attr == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (attr == NULL) 5 17 22
4126 5 elem = NULL;
4127 17 ▶ else if (attr->type == XML_ATTRIBUTE_NODE)
Branch: 1 branch
BranchTrueFalseTotal
else if (attr->type == XML_ATTRIBUTE_NODE) 17 0 17
4128 17 elem = attr->parent;
4129 0 ▶ else if (attr->type == XML_ELEMENT_NODE)
Branch: 1 branch
BranchTrueFalseTotal
else if (attr->type == XML_ELEMENT_NODE) 0 0 0
4130 0 elem = (xmlNodePtr) attr;
4131 else
4132 0 elem = NULL;
4133 22 ▶ if (elem != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (elem != NULL) { 17 5 22
4134 17 RETVAL = PmmNodeToSv(elem, PmmPROXYNODE(self));
4135 }
4136 else {
4137 5 XSRETURN_UNDEF;
4138 }
4139 }
4140 else {
4141 0 XSRETURN_UNDEF;
4142 }
4143 OUTPUT:
4144 RETVAL
4145  
4146 int
4147 indexElements ( self )
4148 xmlDocPtr self
4149 CODE:
4150 #if LIBXML_VERSION >= 20508
4151 0 ▶ RETVAL = xmlXPathOrderDocElems( self );
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = xmlXPathOrderDocElems( self ); 0 0 0
4152 #else
4153 RETVAL = -2;
4154 #endif
4155 OUTPUT:
4156 RETVAL
4157  
4158 MODULE = XML::LibXML PACKAGE = XML::LibXML::Node
4159  
4160 void
4161 DESTROY( node )
4162 SV * node
4163 PREINIT:
4164 int count;
4165 SV *is_shared;
4166 CODE:
4167 #ifdef XML_LIBXML_THREADS
4168 if ( (is_shared = get_sv("XML::LibXML::__threads_shared", 0)) == NULL ) {
4169 is_shared = &PL_sv_undef;
4170 }
4171 if ( SvTRUE(is_shared) ) {
4172 dSP;
4173 ENTER;
4174 SAVETMPS;
4175 PUSHMARK(SP);
4176 XPUSHs(node);
4177 PUTBACK;
4178 count = call_pv("threads::shared::is_shared", G_SCALAR);
4179 SPAGAIN;
4180 if (count != 1)
4181 croak("Couldn't checks if the variable is shared or not\n");
4182 is_shared = POPs;
4183 PUTBACK;
4184 FREETMPS;
4185 LEAVE;
4186 if (is_shared != &PL_sv_undef) {
4187 XSRETURN_UNDEF;
4188 }
4189 }
4190 if( PmmUSEREGISTRY ) {
4191 SvLOCK(PROXY_NODE_REGISTRY_MUTEX);
4192 PmmRegistryREFCNT_dec(SvPROXYNODE(node));
4193 }
4194 #endif
4195 20510 PmmREFCNT_dec(SvPROXYNODE(node));
4196 #ifdef XML_LIBXML_THREADS
4197 if( PmmUSEREGISTRY )
4198 SvUNLOCK(PROXY_NODE_REGISTRY_MUTEX);
4199 #endif
4200  
4201 SV*
4202 nodeName( self )
4203 xmlNodePtr self
4204 ALIAS:
4205 XML::LibXML::Node::getName = 1
4206 XML::LibXML::Element::tagName = 2
4207 PREINIT:
4208 253 xmlChar * name = NULL;
4209 CODE:
4210 PERL_UNUSED_VAR(ix);
4211 253 name = (xmlChar*)domName( self );
4212 253 ▶ if ( name != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name != NULL ) { 253 0 253
4213 253 RETVAL = C2Sv(name,NULL);
4214 253 xmlFree( name );
4215 }
4216 else {
4217 0 XSRETURN_UNDEF;
4218 }
4219 OUTPUT:
4220 RETVAL
4221  
4222 SV*
4223 localname( self )
4224 xmlNodePtr self
4225 ALIAS:
4226 XML::LibXML::Node::getLocalName = 1
4227 XML::LibXML::Attr::name = 2
4228 XML::LibXML::Node::localName = 3
4229 CODE:
4230 PERL_UNUSED_VAR(ix);
4231 126 ▶ if ( self->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type == XML_ELEMENT_NODE 55 71 126
4232 55 ▶ || self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_NODE 0 55 55
4233 0 ▶ || self->type == XML_ELEMENT_DECL
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ELEMENT_DECL 0 0 0
4234 0 ▶ || self->type == XML_ATTRIBUTE_DECL ) {
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_DECL ) { 0 0 0
4235 126 RETVAL = C2Sv(self->name,NULL);
4236 }
4237 else {
4238 0 XSRETURN_UNDEF;
4239 }
4240 OUTPUT:
4241 RETVAL
4242  
4243 SV*
4244 prefix( self )
4245 xmlNodePtr self
4246 ALIAS:
4247 XML::LibXML::Node::getPrefix = 1
4248 CODE:
4249 PERL_UNUSED_VAR(ix);
4250 58 ▶ if( ( self->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if( ( self->type == XML_ELEMENT_NODE 14 44 58
4251 14 ▶ || self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_NODE 0 14 14
4252 0 ▶ || self->type == XML_PI_NODE )
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_PI_NODE ) 0 0 0
4253 58 ▶ && self->ns != NULL
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns != NULL 11 47 58
4254 11 ▶ && self->ns->prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns->prefix != NULL ) { 6 5 11
4255 6 RETVAL = C2Sv(self->ns->prefix, NULL);
4256 }
4257 else {
4258 52 XSRETURN_UNDEF;
4259 }
4260 OUTPUT:
4261 RETVAL
4262  
4263 SV*
4264 namespaceURI( self )
4265 xmlNodePtr self
4266 ALIAS:
4267 getNamespaceURI = 1
4268 PREINIT:
4269 xmlChar * nsURI;
4270 CODE:
4271 PERL_UNUSED_VAR(ix);
4272 77 ▶ if ( ( self->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( ( self->type == XML_ELEMENT_NODE 26 51 77
4273 26 ▶ || self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_NODE 0 26 26
4274 0 ▶ || self->type == XML_PI_NODE )
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_PI_NODE ) 0 0 0
4275 77 ▶ && self->ns != NULL
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns != NULL 25 52 77
4276 25 ▶ && self->ns->href != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns->href != NULL ) { 25 0 25
4277 25 nsURI = xmlStrdup(self->ns->href);
4278 25 RETVAL = C2Sv( nsURI, NULL );
4279 25 xmlFree( nsURI );
4280 }
4281 else {
4282 52 XSRETURN_UNDEF;
4283 }
4284 OUTPUT:
4285 RETVAL
4286  
4287  
4288 SV*
4289 lookupNamespaceURI( self, svprefix=&PL_sv_undef )
4290 xmlNodePtr self
4291 SV * svprefix
4292 PREINIT:
4293 xmlChar * nsURI;
4294 23 xmlChar * prefix = NULL;
4295 xmlNsPtr ns;
4296 CODE:
4297 23 prefix = nodeSv2C( svprefix , self );
4298 23 ▶ if ( prefix != NULL && xmlStrlen(prefix) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 22 1 23
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 5 17 22
4299 5 xmlFree( prefix );
4300 5 prefix = NULL;
4301 }
4302 23 ns = xmlSearchNs( self->doc, self, prefix );
4303 23 ▶ if ( prefix != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL) { 17 6 23
4304 17 xmlFree( prefix );
4305 }
4306 23 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 16 7 23
4307 16 nsURI = xmlStrdup(ns->href);
4308 16 RETVAL = C2Sv( nsURI, NULL );
4309 16 xmlFree( nsURI );
4310 }
4311 else {
4312 7 XSRETURN_UNDEF;
4313 }
4314 OUTPUT:
4315 RETVAL
4316  
4317 SV*
4318 lookupNamespacePrefix( self, svuri )
4319 xmlNodePtr self
4320 SV * svuri
4321 PREINIT:
4322 xmlChar * nsprefix;
4323 7 xmlChar * href = NULL;
4324 CODE:
4325 7 href = nodeSv2C( svuri , self );
4326 11 ▶ if ( href != NULL && xmlStrlen(href) > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( href != NULL && xmlStrlen(href) > 0) { 7 0 7
if ( href != NULL && xmlStrlen(href) > 0) { 7 0 7
4327 7 xmlNsPtr ns = xmlSearchNsByHref( self->doc, self, href );
4328 7 xmlFree( href );
4329 7 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 4 3 7
4330 4 ▶ if ( ns->prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns->prefix != NULL ) { 3 1 4
4331 3 nsprefix = xmlStrdup( ns->prefix );
4332 3 RETVAL = C2Sv( nsprefix, NULL );
4333 3 xmlFree(nsprefix);
4334 } else {
4335 1 RETVAL = newSVpv("",0);
4336 }
4337 }
4338 else {
4339 3 XSRETURN_UNDEF;
4340 }
4341 }
4342 else {
4343 0 XSRETURN_UNDEF;
4344 }
4345 OUTPUT:
4346 RETVAL
4347  
4348  
4349 void
4350 setNodeName( self , value )
4351 xmlNodePtr self
4352 SV* value
4353 ALIAS:
4354 setName = 1
4355 PREINIT:
4356 xmlChar* string;
4357 xmlChar* localname;
4358 xmlChar* prefix;
4359 CODE:
4360 PERL_UNUSED_VAR(ix);
4361 11 string = nodeSv2C( value , self );
4362 11 ▶ if ( !LibXML_test_node_name( string ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name( string ) ) { 4 7 11
4363 4 xmlFree(string);
4364 4 croak( "bad name" );
4365 }
4366 7 ▶ if( ( self->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if( ( self->type == XML_ELEMENT_NODE 2 5 7
4367 2 ▶ || self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_NODE 0 2 2
4368 0 ▶ || self->type == XML_PI_NODE)
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_PI_NODE) 0 0 0
4369 7 ▶ && self->ns ){
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns ){ 5 2 7
4370 5 localname = xmlSplitQName2(string, &prefix);
4371 5 ▶ if ( localname == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname == NULL ) { 3 2 5
4372 3 localname = xmlStrdup( string );
4373 }
4374 5 xmlNodeSetName(self, localname );
4375 5 xmlFree(localname);
4376 5 xmlFree(prefix);
4377 }
4378 else {
4379 xs_warn("node name normal\n");
4380 2 xmlNodeSetName(self, string );
4381 }
4382 7 xmlFree(string);
4383  
4384 void
4385 setRawName( self, value )
4386 xmlNodePtr self
4387 SV * value
4388 PREINIT:
4389 xmlChar* string;
4390 xmlChar* localname;
4391 xmlChar* prefix;
4392 CODE:
4393 0 string = nodeSv2C( value , self );
4394 0 ▶ if ( !string || xmlStrlen( string) <= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !string || xmlStrlen( string) <= 0 ) { 0 0 0
if ( !string || xmlStrlen( string) <= 0 ) { 0 0 0
4395 0 xmlFree(string);
4396 0 XSRETURN_UNDEF;
4397 }
4398 0 ▶ if( ( self->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if( ( self->type == XML_ELEMENT_NODE 0 0 0
4399 0 ▶ || self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_ATTRIBUTE_NODE 0 0 0
4400 0 ▶ || self->type == XML_PI_NODE)
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_PI_NODE) 0 0 0
4401 0 ▶ && self->ns ){
Branch: 1 branch
BranchTrueFalseTotal
&& self->ns ){ 0 0 0
4402 0 localname = xmlSplitQName2(string, &prefix);
4403 0 xmlNodeSetName(self, localname );
4404 0 xmlFree(localname);
4405 0 xmlFree(prefix);
4406 }
4407 else {
4408 0 xmlNodeSetName(self, string );
4409 }
4410 0 xmlFree(string);
4411  
4412  
4413 SV*
4414 nodeValue( self, useDomEncoding = &PL_sv_undef )
4415 xmlNodePtr self
4416 SV * useDomEncoding
4417 ALIAS:
4418 XML::LibXML::Attr::value = 1
4419 XML::LibXML::Attr::getValue = 2
4420 XML::LibXML::Text::data = 3
4421 XML::LibXML::Node::getValue = 4
4422 XML::LibXML::Node::getData = 5
4423 PREINIT:
4424 172 xmlChar * content = NULL;
4425 CODE:
4426 PERL_UNUSED_VAR(ix);
4427 171 content = domGetNodeValue( self );
4428  
4429 171 ▶ if ( content != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( content != NULL ) { 169 2 171
4430 169 ▶ if ( SvTRUE(useDomEncoding) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( SvTRUE(useDomEncoding) ) { 0 169 169
4431 0 RETVAL = nodeC2Sv(content, self);
4432 }
4433 else {
4434 169 RETVAL = C2Sv(content, NULL);
4435 }
4436 169 xmlFree(content);
4437 }
4438 else {
4439 2 XSRETURN_UNDEF;
4440 }
4441 OUTPUT:
4442 RETVAL
4443  
4444 int
4445 nodeType( self )
4446 xmlNodePtr self
4447 ALIAS:
4448 XML::LibXML::Node::getType = 1
4449 CODE:
4450 PERL_UNUSED_VAR(ix);
4451 213 ▶ RETVAL = self->type;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->type; 177 36 213
4452 OUTPUT:
4453 RETVAL
4454  
4455 SV*
4456 parentNode( self )
4457 xmlNodePtr self
4458 ALIAS:
4459 XML::LibXML::Attr::ownerElement = 1
4460 XML::LibXML::Node::getParentNode = 2
4461 XML::LibXML::Attr::getOwnerElement = 3
4462 CODE:
4463 PERL_UNUSED_VAR(ix);
4464 158 RETVAL = PmmNodeToSv( self->parent,
4465 158 ▶ PmmOWNERPO( PmmPROXYNODE(self) ) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO( PmmPROXYNODE(self) ) ); 158 0 158
PmmOWNERPO( PmmPROXYNODE(self) ) ); 158 0 158
4466 OUTPUT:
4467 RETVAL
4468  
4469 SV*
4470 nextSibling( self )
4471 xmlNodePtr self
4472 ALIAS:
4473 getNextSibling = 1
4474 CODE:
4475 PERL_UNUSED_VAR(ix);
4476 15 RETVAL = PmmNodeToSv( self->next,
4477 15 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 15 0 15
PmmOWNERPO(PmmPROXYNODE(self)) ); 15 0 15
4478 OUTPUT:
4479 RETVAL
4480  
4481 SV*
4482 nextNonBlankSibling( self )
4483 xmlNodePtr self
4484 PREINIT:
4485 xmlNodePtr next;
4486 CODE:
4487 14 next = self->next;
4488 28 ▶ while (next != NULL && xmlIsBlankNode(next))
Branch: 2 branches
BranchTrueFalseTotal
while (next != NULL && xmlIsBlankNode(next)) 26 2 28
while (next != NULL && xmlIsBlankNode(next)) 14 12 26
4489 14 next = next->next;
4490 14 RETVAL = PmmNodeToSv( next,
4491 14 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 14 0 14
PmmOWNERPO(PmmPROXYNODE(self)) ); 14 0 14
4492 OUTPUT:
4493 RETVAL
4494  
4495  
4496 SV*
4497 previousSibling( self )
4498 xmlNodePtr self
4499 ALIAS:
4500 getPreviousSibling = 1
4501 CODE:
4502 PERL_UNUSED_VAR(ix);
4503 4 RETVAL = PmmNodeToSv( self->prev,
4504 4 ▶ PmmOWNERPO( PmmPROXYNODE(self) ) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO( PmmPROXYNODE(self) ) ); 4 0 4
PmmOWNERPO( PmmPROXYNODE(self) ) ); 4 0 4
4505 OUTPUT:
4506 RETVAL
4507  
4508 SV*
4509 previousNonBlankSibling( self )
4510 xmlNodePtr self
4511 PREINIT:
4512 xmlNodePtr prev;
4513 CODE:
4514 14 prev = self->prev;
4515 30 ▶ while (prev != NULL && xmlIsBlankNode(prev))
Branch: 2 branches
BranchTrueFalseTotal
while (prev != NULL && xmlIsBlankNode(prev)) 28 2 30
while (prev != NULL && xmlIsBlankNode(prev)) 16 12 28
4516 16 prev = prev->prev;
4517 14 RETVAL = PmmNodeToSv( prev,
4518 14 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 14 0 14
PmmOWNERPO(PmmPROXYNODE(self)) ); 14 0 14
4519 OUTPUT:
4520 RETVAL
4521  
4522  
4523 void
4524 _childNodes( self, only_nonblank = 0 )
4525 xmlNodePtr self
4526 int only_nonblank
4527 ALIAS:
4528 XML::LibXML::Node::getChildnodes = 1
4529 PREINIT:
4530 xmlNodePtr cld;
4531 SV * element;
4532 165 int len = 0;
4533 165 int wantarray = GIMME_V;
4534 PPCODE:
4535 PERL_UNUSED_VAR(ix);
4536 165 ▶ if ( self->type != XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type != XML_ATTRIBUTE_NODE ) { 165 0 165
4537 165 cld = self->children;
4538 xs_warn("childnodes start");
4539 620 ▶ while ( cld ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( cld ) { 455 165 620
4540 455 ▶ if ( !(only_nonblank && xmlIsBlankNode(cld)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !(only_nonblank && xmlIsBlankNode(cld)) ) { 30 425 455
if ( !(only_nonblank && xmlIsBlankNode(cld)) ) { 14 16 30
4541 439 ▶ if( wantarray != G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if( wantarray != G_SCALAR ) { 439 0 439
4542 439 ▶ element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) ); 439 0 439
element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) ); 315 124 439
4543 439 ▶ XPUSHs(sv_2mortal(element));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(element)); 0 439 439
4544 }
4545 439 len++;
4546 }
4547 455 cld = cld->next;
4548 }
4549 }
4550 165 ▶ if ( wantarray == G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( wantarray == G_SCALAR ) { 0 165 165
4551 0 ▶ XPUSHs(sv_2mortal(newSViv(len)) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(len)) ); 0 0 0
4552 }
4553  
4554 void
4555 _getChildrenByTagNameNS( self, namespaceURI, node_name )
4556 xmlNodePtr self
4557 SV * namespaceURI
4558 SV * node_name
4559 PREINIT:
4560 xmlChar * name;
4561 xmlChar * nsURI;
4562 xmlNodePtr cld;
4563 SV * element;
4564 12 int len = 0;
4565 12 int name_wildcard = 0;
4566 12 int ns_wildcard = 0;
4567 12 int wantarray = GIMME_V;
4568 PPCODE:
4569 12 name = nodeSv2C(node_name, self );
4570 12 nsURI = nodeSv2C(namespaceURI, self );
4571  
4572 12 ▶ if ( nsURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI != NULL ) { 12 0 12
4573 12 ▶ if (xmlStrlen(nsURI) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (xmlStrlen(nsURI) == 0 ) { 0 12 12
4574 0 xmlFree(nsURI);
4575 0 nsURI = NULL;
4576 12 ▶ } else if (xmlStrcmp( nsURI, (xmlChar *)"*" )==0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (xmlStrcmp( nsURI, (xmlChar *)"*" )==0) { 9 3 12
4577 9 ns_wildcard = 1;
4578 }
4579 }
4580 12 ▶ if ( name !=NULL && xmlStrcmp( name, (xmlChar *)"*" ) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( name !=NULL && xmlStrcmp( name, (xmlChar *)"*" ) == 0) { 12 0 12
if ( name !=NULL && xmlStrcmp( name, (xmlChar *)"*" ) == 0) { 6 6 12
4581 6 name_wildcard = 1;
4582 }
4583 12 ▶ if ( self->type != XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type != XML_ATTRIBUTE_NODE ) { 12 0 12
4584 12 cld = self->children;
4585 xs_warn("childnodes start");
4586 48 ▶ while ( cld ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( cld ) { 36 12 48
4587 60 ▶ if (((name_wildcard && (cld->type == XML_ELEMENT_NODE)) ||
Branch: 1 branch
BranchTrueFalseTotal
if (((name_wildcard && (cld->type == XML_ELEMENT_NODE)) || 18 18 36
4588 24 xmlStrcmp( name, cld->name ) == 0)
4589 24 ▶ && (ns_wildcard ||
Branch: 1 branch
BranchTrueFalseTotal
&& (ns_wildcard || 6 18 24
4590 9 (cld->ns != NULL &&
4591 3 xmlStrcmp(nsURI,cld->ns->href) == 0 ) ||
4592 3 ▶ (cld->ns == NULL && nsURI == NULL))) {
Branch: 2 branches
BranchTrueFalseTotal
(cld->ns == NULL && nsURI == NULL))) { 3 0 3
(cld->ns == NULL && nsURI == NULL))) { 0 3 3
4593 21 ▶ if( wantarray != G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if( wantarray != G_SCALAR ) { 21 0 21
4594 21 ▶ element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) ); 21 0 21
element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) ); 21 0 21
4595 21 ▶ XPUSHs(sv_2mortal(element));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(element)); 0 21 21
4596 }
4597 21 len++;
4598 }
4599 36 cld = cld->next;
4600 }
4601 }
4602 12 ▶ if ( wantarray == G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( wantarray == G_SCALAR ) { 0 12 12
4603 0 ▶ XPUSHs(sv_2mortal(newSViv(len)) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(len)) ); 0 0 0
4604 }
4605 12 xmlFree(name);
4606 12 ▶ if (nsURI) xmlFree(nsURI);
Branch: 1 branch
BranchTrueFalseTotal
if (nsURI) xmlFree(nsURI); 12 0 12
4607  
4608 SV*
4609 firstChild( self )
4610 xmlNodePtr self
4611 ALIAS:
4612 getFirstChild = 1
4613 CODE:
4614 PERL_UNUSED_VAR(ix);
4615 51 RETVAL = PmmNodeToSv( self->children,
4616 51 ▶ PmmOWNERPO( PmmPROXYNODE(self) ) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO( PmmPROXYNODE(self) ) ); 51 0 51
PmmOWNERPO( PmmPROXYNODE(self) ) ); 20 31 51
4617 OUTPUT:
4618 RETVAL
4619  
4620 SV*
4621 firstNonBlankChild( self )
4622 xmlNodePtr self
4623 PREINIT:
4624 xmlNodePtr child;
4625 CODE:
4626 2 child = self->children;
4627 4 ▶ while (child !=NULL && xmlIsBlankNode(child))
Branch: 2 branches
BranchTrueFalseTotal
while (child !=NULL && xmlIsBlankNode(child)) 4 0 4
while (child !=NULL && xmlIsBlankNode(child)) 2 2 4
4628 2 child = child->next;
4629 2 RETVAL = PmmNodeToSv( child,
4630 2 ▶ PmmOWNERPO( PmmPROXYNODE(self) ) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO( PmmPROXYNODE(self) ) ); 2 0 2
PmmOWNERPO( PmmPROXYNODE(self) ) ); 2 0 2
4631 OUTPUT:
4632 RETVAL
4633  
4634 SV*
4635 lastChild( self )
4636 xmlNodePtr self
4637 ALIAS:
4638 getLastChild = 1
4639 CODE:
4640 PERL_UNUSED_VAR(ix);
4641 28 RETVAL = PmmNodeToSv( self->last,
4642 28 ▶ PmmOWNERPO( PmmPROXYNODE(self) ) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO( PmmPROXYNODE(self) ) ); 28 0 28
PmmOWNERPO( PmmPROXYNODE(self) ) ); 3 25 28
4643 OUTPUT:
4644 RETVAL
4645  
4646 void
4647 _attributes( self )
4648 xmlNodePtr self
4649 ALIAS:
4650 XML::LibXML::Node::getAttributes = 1
4651 PREINIT:
4652 51 xmlAttrPtr attr = NULL;
4653 51 xmlNsPtr ns = NULL;
4654 SV * element;
4655 51 int len=0;
4656 51 int wantarray = GIMME_V;
4657 PPCODE:
4658 PERL_UNUSED_VAR(ix);
4659 51 ▶ if ( self->type != XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type != XML_ATTRIBUTE_NODE 51 0 51
4660 51 ▶ && self->type != XML_DTD_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
&& self->type != XML_DTD_NODE ) { 50 1 51
4661 50 attr = self->properties;
4662 83 ▶ while ( attr != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( attr != NULL ) { 33 50 83
4663 33 ▶ if ( wantarray != G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( wantarray != G_SCALAR ) { 33 0 33
4664 33 element = PmmNodeToSv((xmlNodePtr)attr,
4665 33 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 33 0 33
PmmOWNERPO(PmmPROXYNODE(self)) ); 33 0 33
4666 33 ▶ XPUSHs(sv_2mortal(element));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(element)); 0 33 33
4667 }
4668 33 attr = attr->next;
4669 33 len++;
4670 }
4671 50 ▶ if (self->type == XML_ELEMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->type == XML_ELEMENT_NODE) { 50 0 50
4672 50 ns = self->nsDef;
4673 64 ▶ while ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ns != NULL ) { 14 50 64
4674 14 const char * CLASS = "XML::LibXML::Namespace";
4675 14 ▶ if ( wantarray != G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( wantarray != G_SCALAR ) { 14 0 14
4676 /* namespace handling is kinda odd:
4677 * as soon we have a namespace isolated from its
4678 * owner, we loose the context. therefore it is
4679 * forbidden to access the NS information directly.
4680 * instead the use will receive a copy of the real
4681 * namespace, that can be destroied and is not
4682 * bound to a document.
4683 *
4684 * this avoids segfaults in the end.
4685 */
4686 14 ▶ if ((ns->prefix != NULL || ns->href != NULL)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((ns->prefix != NULL || ns->href != NULL)) { 2 12 14
if ((ns->prefix != NULL || ns->href != NULL)) { 2 0 2
4687 14 xmlNsPtr tns = xmlCopyNamespace(ns);
4688 14 ▶ if ( tns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( tns != NULL ) { 14 0 14
4689 14 element = sv_newmortal();
4690 14 ▶ XPUSHs(sv_setref_pv( element,
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_setref_pv( element, 0 14 14
4691 (char *)CLASS,
4692 (void*)tns));
4693 }
4694 }
4695 }
4696 14 ns = ns->next;
4697 14 len++;
4698 }
4699 }
4700 }
4701 51 ▶ if( wantarray == G_SCALAR ) {
Branch: 1 branch
BranchTrueFalseTotal
if( wantarray == G_SCALAR ) { 0 51 51
4702 0 ▶ XPUSHs( sv_2mortal(newSViv(len)) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(newSViv(len)) ); 0 0 0
4703 }
4704  
4705 int
4706 hasChildNodes( self )
4707 xmlNodePtr self
4708 CODE:
4709 125 ▶ if ( self->type == XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type == XML_ATTRIBUTE_NODE ) { 2 123 125
4710 2 RETVAL = 0;
4711 }
4712 else {
4713 123 RETVAL = self->children ? 1 : 0 ;
4714 }
4715 OUTPUT:
4716 RETVAL
4717  
4718 int
4719 hasAttributes( self )
4720 xmlNodePtr self
4721 CODE:
4722 2 ▶ if ( self->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type == XML_ATTRIBUTE_NODE 2 0 2
4723 2 ▶ || self->type == XML_DTD_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_DTD_NODE ) { 1 1 2
4724 1 RETVAL = 0;
4725 }
4726 else {
4727 1 RETVAL = self->properties ? 1 : 0 ;
4728 }
4729 OUTPUT:
4730 RETVAL
4731  
4732 SV*
4733 ownerDocument( self )
4734 xmlNodePtr self
4735 ALIAS:
4736 XML::LibXML::Node::getOwnerDocument = 1
4737 CODE:
4738 PERL_UNUSED_VAR(ix);
4739 xs_warn( "GET OWNERDOC\n" );
4740 19 ▶ if( self != NULL
Branch: 1 branch
BranchTrueFalseTotal
if( self != NULL 19 0 19
4741 19 ▶ && self->doc != NULL ){
Branch: 1 branch
BranchTrueFalseTotal
&& self->doc != NULL ){ 17 2 19
4742 17 RETVAL = PmmNodeToSv((xmlNodePtr)(self->doc), NULL);
4743 }
4744 else {
4745 2 XSRETURN_UNDEF;
4746 }
4747 OUTPUT:
4748 RETVAL
4749  
4750 SV*
4751 ownerNode( self )
4752 xmlNodePtr self
4753 ALIAS:
4754 XML::LibXML::Node::getOwner = 1
4755 XML::LibXML::Node::getOwnerElement = 2
4756 CODE:
4757 PERL_UNUSED_VAR(ix);
4758 0 ▶ RETVAL = PmmNodeToSv(PmmNODE(PmmOWNERPO(PmmPROXYNODE(self))), NULL);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = PmmNodeToSv(PmmNODE(PmmOWNERPO(PmmPROXYNODE(self))), NULL); 0 0 0
RETVAL = PmmNodeToSv(PmmNODE(PmmOWNERPO(PmmPROXYNODE(self))), NULL); 0 0 0
4759 OUTPUT:
4760 RETVAL
4761  
4762  
4763 void
4764 normalize( self )
4765 xmlNodePtr self
4766 CODE:
4767 3 domNodeNormalize( self );
4768  
4769  
4770 SV*
4771 insertBefore( self, nNode, refNode )
4772 xmlNodePtr self
4773 xmlNodePtr nNode
4774 SV * refNode
4775 PREINIT:
4776 9 xmlNodePtr oNode=NULL, rNode;
4777 INIT:
4778 9 oNode = PmmSvNode(refNode);
4779 CODE:
4780 9 rNode = domInsertBefore( self, nNode, oNode );
4781 8 ▶ if ( rNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rNode != NULL ) { 8 0 8
4782 8 RETVAL = PmmNodeToSv( rNode,
4783 8 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 8 0 8
PmmOWNERPO(PmmPROXYNODE(self)) ); 5 3 8
4784 8 ▶ if (rNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (rNode->type == XML_DTD_NODE) { 2 6 8
4785 2 LibXML_set_int_subset(self->doc, rNode);
4786 }
4787 8 ▶ PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self)));
Branch: 2 branches
BranchTrueFalseTotal
PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self))); 8 0 8
PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self))); 5 3 8
4788 }
4789 else {
4790 0 XSRETURN_UNDEF;
4791 }
4792 OUTPUT:
4793 RETVAL
4794  
4795 SV*
4796 insertAfter( self, nNode, refNode )
4797 xmlNodePtr self
4798 xmlNodePtr nNode
4799 SV* refNode
4800 PREINIT:
4801 6 xmlNodePtr oNode = NULL, rNode;
4802 INIT:
4803 6 oNode = PmmSvNode(refNode);
4804 CODE:
4805 6 rNode = domInsertAfter( self, nNode, oNode );
4806 6 ▶ if ( rNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rNode != NULL ) { 6 0 6
4807 6 RETVAL = PmmNodeToSv( rNode,
4808 6 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 6 0 6
PmmOWNERPO(PmmPROXYNODE(self)) ); 3 3 6
4809 6 ▶ if (rNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (rNode->type == XML_DTD_NODE) { 2 4 6
4810 2 LibXML_set_int_subset(self->doc, rNode);
4811 }
4812 6 ▶ PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self)));
Branch: 2 branches
BranchTrueFalseTotal
PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self))); 6 0 6
PmmFixOwner(PmmPROXYNODE(rNode), PmmOWNERPO(PmmPROXYNODE(self))); 3 3 6
4813 }
4814 else {
4815 0 XSRETURN_UNDEF;
4816 }
4817 OUTPUT:
4818 RETVAL
4819  
4820 SV*
4821 replaceChild( self, nNode, oNode )
4822 xmlNodePtr self
4823 xmlNodePtr nNode
4824 xmlNodePtr oNode
4825 PREINIT:
4826 5 xmlNodePtr ret = NULL;
4827 CODE:
4828 // if newNode == oldNode or self == newNode then do nothing, just return nNode.
4829 5 ▶ if (nNode == oNode || self == nNode ) {
Branch: 2 branches
BranchTrueFalseTotal
if (nNode == oNode || self == nNode ) { 5 0 5
if (nNode == oNode || self == nNode ) { 0 5 5
4830 0 ret = nNode;
4831 0 ▶ RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret)));
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 0 0 0
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 0 0 0
4832 }
4833 else{
4834 5 ▶ if ( self->type == XML_DOCUMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type == XML_DOCUMENT_NODE ) { 2 3 5
4835 2 switch ( nNode->type ) {
4836 0 case XML_ELEMENT_NODE:
4837 0 warn("replaceChild with an element on a document node not supported yet!");
4838 0 XSRETURN_UNDEF;
4839 break;
4840 0 case XML_DOCUMENT_FRAG_NODE:
4841 0 warn("replaceChild with a document fragment node on a document node not supported yet!");
4842 0 XSRETURN_UNDEF;
4843 break;
4844 0 case XML_TEXT_NODE:
4845 case XML_CDATA_SECTION_NODE:
4846 0 warn("replaceChild with a text node not supported on a document node!");
4847 0 XSRETURN_UNDEF;
4848 break;
4849 2 default:
4850 2 break;
4851 }
4852 }
4853 5 ret = domReplaceChild( self, nNode, oNode );
4854 5 ▶ if (ret == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret == NULL) { 0 5 5
4855 0 XSRETURN_UNDEF;
4856 }
4857 else {
4858 5 LibXML_reparent_removed_node(ret);
4859 5 ▶ RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret)));
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 5 0 5
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 5 0 5
4860 5 ▶ if (nNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (nNode->type == XML_DTD_NODE) { 2 3 5
4861 2 LibXML_set_int_subset(nNode->doc, nNode);
4862 }
4863 5 ▶ if ( nNode->_private != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nNode->_private != NULL ) { 5 0 5
4864 5 PmmFixOwner( PmmPROXYNODE(nNode),
4865 5 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 5 0 5
PmmOWNERPO(PmmPROXYNODE(self)) ); 3 2 5
4866 }
4867 }
4868 }
4869 OUTPUT:
4870 RETVAL
4871  
4872 SV*
4873 replaceNode( self,nNode )
4874 xmlNodePtr self
4875 xmlNodePtr nNode
4876 PREINIT:
4877 5 xmlNodePtr ret = NULL;
4878 5 ProxyNodePtr owner = NULL;
4879 CODE:
4880 5 ▶ if ( domIsParent( self, nNode ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( domIsParent( self, nNode ) == 1 ) { 0 5 5
4881 0 XSRETURN_UNDEF;
4882 }
4883 5 ▶ owner = PmmOWNERPO(PmmPROXYNODE(self));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(PmmPROXYNODE(self)); 5 0 5
owner = PmmOWNERPO(PmmPROXYNODE(self)); 5 0 5
4884  
4885 5 ▶ if ( self->type != XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type != XML_ATTRIBUTE_NODE ) { 4 1 5
4886 4 ret = domReplaceChild( self->parent, nNode, self);
4887 }
4888 else {
4889 1 ret = xmlReplaceNode( self, nNode );
4890 }
4891 5 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 5 0 5
4892 5 LibXML_reparent_removed_node(ret);
4893 5 ▶ RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret)));
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 5 0 5
RETVAL = PmmNodeToSv(ret, PmmOWNERPO(PmmPROXYNODE(ret))); 5 0 5
4894 5 ▶ if (nNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (nNode->type == XML_DTD_NODE) { 3 2 5
4895 3 LibXML_set_int_subset(nNode->doc, nNode);
4896 }
4897 5 ▶ if ( nNode->_private != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nNode->_private != NULL ) { 5 0 5
4898 5 PmmFixOwner(PmmPROXYNODE(nNode), owner);
4899 }
4900 }
4901 else {
4902 0 croak( "replacement failed" );
4903 XSRETURN_UNDEF;
4904 }
4905 OUTPUT:
4906 RETVAL
4907  
4908 SV*
4909 removeChild( self, node )
4910 xmlNodePtr self
4911 xmlNodePtr node
4912 PREINIT:
4913 xmlNodePtr ret;
4914 CODE:
4915 15 ret = domRemoveChild( self, node );
4916 15 ▶ if (ret == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret == NULL) { 1 14 15
4917 1 XSRETURN_UNDEF;
4918 }
4919 else {
4920 14 LibXML_reparent_removed_node(ret);
4921 14 RETVAL = PmmNodeToSv(ret, NULL);
4922 }
4923 OUTPUT:
4924 RETVAL
4925  
4926 void
4927 removeChildNodes( self )
4928 xmlNodePtr self
4929 PREINIT:
4930 xmlNodePtr elem, fragment;
4931 ProxyNodePtr docfrag;
4932 CODE:
4933 2 docfrag = PmmNewFragment( self->doc );
4934 2 fragment = PmmNODE( docfrag );
4935 2 elem = self->children;
4936 6 ▶ while ( elem ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( elem ) { 4 2 6
4937 4 xmlNodePtr next = elem->next;
4938 4 xmlUnlinkNode( elem );
4939 4 ▶ if (elem->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
if (elem->type == XML_ATTRIBUTE_NODE 4 0 4
4940 4 ▶ || elem->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
|| elem->type == XML_DTD_NODE) { 1 3 4
4941 1 ▶ if (PmmPROXYNODE(elem) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (PmmPROXYNODE(elem) == NULL) { 0 1 1
4942 0 xmlFreeNode(elem);
4943 }
4944 }
4945 else {
4946 /* this following piece is the function of domAppendChild()
4947 * but in this special case we can avoid most of the logic of
4948 * that function.
4949 */
4950 3 ▶ if ( fragment->children != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( fragment->children != NULL ) { 1 2 3
4951 xs_warn("unlink node!\n");
4952 1 domAddNodeToList( elem, fragment->last, NULL );
4953 }
4954 else {
4955 2 fragment->children = elem;
4956 2 fragment->last = elem;
4957 2 elem->parent= fragment;
4958 }
4959 3 PmmFixOwnerNode( elem, docfrag );
4960 }
4961 4 elem = next;
4962 }
4963  
4964 2 self->children = self->last = NULL;
4965 2 ▶ if ( PmmREFCNT(docfrag) <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( PmmREFCNT(docfrag) <= 0 ) { 2 0 2
4966 xs_warn( "have not references left" );
4967 2 PmmREFCNT_inc( docfrag );
4968 2 PmmREFCNT_dec( docfrag );
4969 }
4970  
4971 void
4972 unbindNode( self )
4973 xmlNodePtr self
4974 ALIAS:
4975 XML::LibXML::Node::unlink = 1
4976 XML::LibXML::Node::unlinkNode = 2
4977 PREINIT:
4978 10 ProxyNodePtr docfrag = NULL;
4979 CODE:
4980 PERL_UNUSED_VAR(ix);
4981 10 ▶ if ( self->type != XML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type != XML_DOCUMENT_NODE 10 0 10
4982 10 ▶ && self->type != XML_DOCUMENT_FRAG_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
&& self->type != XML_DOCUMENT_FRAG_NODE ) { 10 0 10
4983 10 xmlUnlinkNode( self );
4984 10 LibXML_reparent_removed_node(self);
4985 }
4986  
4987 SV*
4988 appendChild( self, nNode )
4989 xmlNodePtr self
4990 xmlNodePtr nNode
4991 PREINIT:
4992 xmlNodePtr rNode;
4993 CODE:
4994 61 ▶ if (self->type == XML_DOCUMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->type == XML_DOCUMENT_NODE ) { 3 58 61
4995 /* NOT_SUPPORTED_ERR
4996 */
4997 3 switch ( nNode->type ) {
4998 1 case XML_ELEMENT_NODE:
4999 1 warn("Appending an element to a document node not supported yet!");
5000 1 XSRETURN_UNDEF;
5001 break;
5002 0 case XML_DOCUMENT_FRAG_NODE:
5003 0 warn("Appending a document fragment node to a document node not supported yet!");
5004 0 XSRETURN_UNDEF;
5005 break;
5006 0 case XML_TEXT_NODE:
5007 case XML_CDATA_SECTION_NODE:
5008 0 warn("Appending text node not supported on a document node yet!");
5009 0 XSRETURN_UNDEF;
5010 break;
5011 2 default:
5012 2 break;
5013 }
5014 }
5015  
5016 60 rNode = domAppendChild( self, nNode );
5017  
5018 59 ▶ if ( rNode == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rNode == NULL ) { 0 59 59
5019 0 XSRETURN_UNDEF;
5020 }
5021  
5022 59 RETVAL = PmmNodeToSv( nNode,
5023 59 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 59 0 59
PmmOWNERPO(PmmPROXYNODE(self)) ); 55 4 59
5024 59 ▶ if (nNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (nNode->type == XML_DTD_NODE) { 1 58 59
5025 1 LibXML_set_int_subset(self->doc, nNode);
5026 }
5027 59 PmmFixOwner( SvPROXYNODE(RETVAL), PmmPROXYNODE(self) );
5028 OUTPUT:
5029 RETVAL
5030  
5031 SV*
5032 addChild( self, nNode )
5033 xmlNodePtr self
5034 xmlNodePtr nNode
5035 PREINIT:
5036 39 xmlNodePtr retval = NULL;
5037 ProxyNodePtr proxy;
5038 CODE:
5039 39 switch ( nNode->type ) {
5040 0 case XML_DOCUMENT_FRAG_NODE:
5041 0 croak("Adding document fragments with addChild not supported!");
5042 XSRETURN_UNDEF;
5043 0 case XML_DOCUMENT_NODE :
5044 case XML_HTML_DOCUMENT_NODE :
5045 case XML_DOCB_DOCUMENT_NODE :
5046 0 croak("addChild: HIERARCHY_REQUEST_ERR\n");
5047 XSRETURN_UNDEF;
5048 0 case XML_NOTATION_NODE :
5049 case XML_NAMESPACE_DECL :
5050 case XML_DTD_NODE :
5051 case XML_DOCUMENT_TYPE_NODE :
5052 case XML_ENTITY_DECL :
5053 case XML_ELEMENT_DECL :
5054 case XML_ATTRIBUTE_DECL :
5055 0 croak("addChild: unsupported node type!");
5056 XSRETURN_UNDEF;
5057 39 default:
5058 39 break;
5059 }
5060  
5061 39 xmlUnlinkNode(nNode);
5062 39 proxy = PmmPROXYNODE(nNode);
5063 39 retval = xmlAddChild( self, nNode );
5064  
5065 39 ▶ if ( retval == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( retval == NULL ) { 0 39 39
5066 0 croak( "Error: addChild failed (check node types)!\n" );
5067 }
5068  
5069 39 ▶ if ( retval != nNode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( retval != nNode ) { 1 38 39
5070 xs_warn( "node was lost during operation\n" );
5071 1 PmmNODE(proxy) = NULL;
5072 }
5073  
5074 39 RETVAL = PmmNodeToSv( retval,
5075 39 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 39 0 39
PmmOWNERPO(PmmPROXYNODE(self)) ); 20 19 39
5076 39 ▶ if ( retval != self ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( retval != self ) { 38 1 39
5077 38 PmmFixOwner( SvPROXYNODE(RETVAL), PmmPROXYNODE(self) );
5078 }
5079 OUTPUT:
5080 RETVAL
5081  
5082  
5083 SV*
5084 addSibling( self, nNode )
5085 xmlNodePtr self
5086 xmlNodePtr nNode
5087 PREINIT:
5088 6 xmlNodePtr ret = NULL;
5089 6 ProxyNodePtr owner = NULL;
5090 CODE:
5091 6 ▶ if ( nNode->type == XML_DOCUMENT_FRAG_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nNode->type == XML_DOCUMENT_FRAG_NODE ) { 0 6 6
5092 0 croak("Adding document fragments with addSibling not yet supported!");
5093 XSRETURN_UNDEF;
5094 }
5095 6 ▶ owner = PmmOWNERPO(PmmPROXYNODE(self));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(PmmPROXYNODE(self)); 6 0 6
owner = PmmOWNERPO(PmmPROXYNODE(self)); 6 0 6
5096  
5097 6 ▶ if (self->type == XML_TEXT_NODE && nNode->type == XML_TEXT_NODE
Branch: 2 branches
BranchTrueFalseTotal
if (self->type == XML_TEXT_NODE && nNode->type == XML_TEXT_NODE 1 5 6
if (self->type == XML_TEXT_NODE && nNode->type == XML_TEXT_NODE 1 0 1
5098 2 ▶ && self->name == nNode->name) {
Branch: 1 branch
BranchTrueFalseTotal
&& self->name == nNode->name) { 1 0 1
5099 /* As a result of text merging, the added node may be freed. */
5100 1 xmlNodePtr copy = xmlCopyNode(nNode, 0);
5101 1 ret = xmlAddSibling(self, copy);
5102  
5103 1 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 1 0 1
5104 1 RETVAL = PmmNodeToSv(ret, owner);
5105 /* Unlink original node. */
5106 1 xmlUnlinkNode(nNode);
5107 1 LibXML_reparent_removed_node(nNode);
5108 }
5109 else {
5110 0 xmlFreeNode(copy);
5111 0 XSRETURN_UNDEF;
5112 }
5113 }
5114 else {
5115 5 ret = xmlAddSibling( self, nNode );
5116  
5117 5 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 5 0 5
5118 5 RETVAL = PmmNodeToSv(ret, owner);
5119 5 ▶ if (nNode->type == XML_DTD_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (nNode->type == XML_DTD_NODE) { 2 3 5
5120 2 LibXML_set_int_subset(self->doc, nNode);
5121 }
5122 5 PmmFixOwner(SvPROXYNODE(RETVAL), owner);
5123 }
5124 else {
5125 0 XSRETURN_UNDEF;
5126 }
5127 }
5128 OUTPUT:
5129 RETVAL
5130  
5131 SV*
5132 cloneNode( self, deep=0 )
5133 xmlNodePtr self
5134 int deep
5135 PREINIT:
5136 xmlNodePtr ret;
5137 6 xmlDocPtr doc = NULL;
5138 6 ProxyNodePtr docfrag = NULL;
5139 CODE:
5140 6 ret = PmmCloneNode( self, deep );
5141 6 ▶ if ( ret == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret == NULL ) { 0 6 6
5142 0 XSRETURN_UNDEF;
5143 }
5144  
5145 6 ▶ if ( ret->type == XML_DTD_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret->type == XML_DTD_NODE ) { 1 5 6
5146 1 RETVAL = PmmNodeToSv(ret, NULL);
5147 }
5148 else {
5149 5 doc = self->doc;
5150  
5151 5 ▶ if ( doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( doc != NULL ) { 5 0 5
5152 5 xmlSetTreeDoc(ret, doc); /* setting to self, no need to clear psvi */
5153 }
5154  
5155 5 docfrag = PmmNewFragment( doc );
5156 5 xmlAddChild( PmmNODE(docfrag), ret );
5157 5 RETVAL = PmmNodeToSv(ret, docfrag);
5158 }
5159 OUTPUT:
5160 RETVAL
5161  
5162 int
5163 isSameNode( self, oNode )
5164 xmlNodePtr self
5165 xmlNodePtr oNode
5166 ALIAS:
5167 XML::LibXML::Node::isEqual = 1
5168 CODE:
5169 PERL_UNUSED_VAR(ix);
5170 152 ▶ RETVAL = ( self == oNode ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( self == oNode ) ? 1 : 0; 52 100 152
5171 OUTPUT:
5172 RETVAL
5173  
5174 IV
5175 unique_key( self )
5176 xmlNodePtr self
5177 CODE:
5178 /* Cast pointer to IV */
5179 50 ▶ RETVAL = PTR2IV(self);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2IV(self); 46 4 50
5180 OUTPUT:
5181 RETVAL
5182  
5183 SV *
5184 baseURI( self )
5185 xmlNodePtr self
5186 PREINIT:
5187 xmlChar * uri;
5188 CODE:
5189 13 uri = xmlNodeGetBase( self->doc, self );
5190 13 RETVAL = C2Sv( uri, NULL );
5191 13 xmlFree( uri );
5192 OUTPUT:
5193 RETVAL
5194  
5195 void
5196 setBaseURI( self, URI )
5197 xmlNodePtr self
5198 SV * URI
5199 PREINIT:
5200 xmlChar * uri;
5201 CODE:
5202 7 uri = nodeSv2C( URI, self );
5203 7 ▶ if ( uri != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( uri != NULL ) { 7 0 7
5204 7 xmlNodeSetBase( self, uri );
5205 }
5206  
5207 SV*
5208 toString( self, format=0, useDomEncoding = &PL_sv_undef )
5209 xmlNodePtr self
5210 SV * useDomEncoding
5211 int format
5212 ALIAS:
5213 XML::LibXML::Node::serialize = 1
5214 PREINIT:
5215 xmlBufferPtr buffer;
5216 157 const xmlChar *ret = NULL;
5217 157 SV* internalFlag = NULL;
5218 157 int oldTagFlag = xmlSaveNoEmptyTags;
5219 CODE:
5220 PERL_UNUSED_VAR(ix);
5221 157 internalFlag = get_sv("XML::LibXML::setTagCompression", 0);
5222  
5223 157 ▶ if ( internalFlag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( internalFlag ) { 157 0 157
5224 157 xmlSaveNoEmptyTags = SvTRUE(internalFlag);
5225 }
5226 157 buffer = xmlBufferCreate();
5227  
5228 157 ▶ if ( format <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( format <= 0 ) { 153 4 157
5229 153 xmlNodeDump( buffer,
5230 153 self->doc,
5231 self, 0, format);
5232 }
5233 else {
5234 4 int t_indent_var = xmlIndentTreeOutput;
5235 4 xmlIndentTreeOutput = 1;
5236 4 xmlNodeDump( buffer,
5237 4 self->doc,
5238 self, 0, format);
5239 4 xmlIndentTreeOutput = t_indent_var;
5240 }
5241  
5242 157 ret = xmlBufferContent( buffer );
5243  
5244 157 xmlSaveNoEmptyTags = oldTagFlag;
5245  
5246 157 ▶ if ( ret != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != NULL ) { 157 0 157
5247 157 ▶ if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 2 155 157
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 2 0 2
5248 2 RETVAL = nodeC2Sv((xmlChar*)ret, PmmNODE(PmmPROXYNODE(self))) ;
5249 2 SvUTF8_off(RETVAL);
5250 }
5251 else {
5252 155 RETVAL = C2Sv((xmlChar*)ret, NULL) ;
5253 }
5254 157 xmlBufferFree( buffer );
5255 }
5256 else {
5257 0 xmlBufferFree( buffer );
5258 xs_warn("Failed to convert node to string");
5259 0 XSRETURN_UNDEF;
5260 }
5261 OUTPUT:
5262 RETVAL
5263  
5264  
5265 SV *
5266 _toStringC14N(self, comments=0, xpath=&PL_sv_undef, exclusive=0, inc_prefix_list=NULL, xpath_context)
5267 xmlNodePtr self
5268 int comments
5269 SV * xpath
5270 int exclusive
5271 char** inc_prefix_list
5272 SV * xpath_context
5273  
5274 PREINIT:
5275 24 xmlChar *result = NULL;
5276 24 xmlChar *nodepath = NULL;
5277 24 xmlXPathContextPtr child_ctxt = NULL;
5278 24 xmlXPathObjectPtr xpath_res = NULL;
5279 24 xmlNodeSetPtr nodelist = NULL;
5280 24 xmlNodePtr refNode = NULL;
5281 24 PREINIT_SAVED_ERROR
5282 INIT:
5283 /* due to how c14n is implemented, the nodeset it receives must
5284 include child nodes; ie, child nodes aren't assumed to be rendered.
5285 so we use an xpath expression to find all of the child nodes. */
5286  
5287 24 ▶ if ( self->doc == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->doc == NULL ) { 0 24 24
5288 0 croak("Node passed to toStringC14N must be part of a document");
5289 }
5290  
5291 24 refNode = self;
5292 CODE:
5293 24 ▶ if ( xpath != NULL && xpath != &PL_sv_undef ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( xpath != NULL && xpath != &PL_sv_undef ) { 24 0 24
if ( xpath != NULL && xpath != &PL_sv_undef ) { 11 13 24
5294 11 nodepath = Sv2C( xpath, NULL );
5295 }
5296  
5297 24 ▶ if ( nodepath != NULL && xmlStrlen( nodepath ) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nodepath != NULL && xmlStrlen( nodepath ) == 0 ) { 11 13 24
if ( nodepath != NULL && xmlStrlen( nodepath ) == 0 ) { 0 11 11
5298 0 xmlFree( nodepath );
5299 0 nodepath = NULL;
5300 }
5301  
5302 24 ▶ if ( nodepath == NULL
Branch: 1 branch
BranchTrueFalseTotal
if ( nodepath == NULL 13 11 24
5303 13 ▶ && self->type != XML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
&& self->type != XML_DOCUMENT_NODE 3 10 13
5304 3 ▶ && self->type != XML_HTML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
&& self->type != XML_HTML_DOCUMENT_NODE 3 0 3
5305 3 ▶ && self->type != XML_DOCB_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
&& self->type != XML_DOCB_DOCUMENT_NODE 3 0 3
5306 ) {
5307 3 ▶ if (comments)
Branch: 1 branch
BranchTrueFalseTotal
if (comments) 0 3 3
5308 0 nodepath = xmlStrdup( (const xmlChar *) "(. | .//node() | .//@* | .//namespace::*)" );
5309 else
5310 3 nodepath = xmlStrdup( (const xmlChar *) "(. | .//node() | .//@* | .//namespace::*)[not(self::comment())]" );
5311 }
5312  
5313 24 ▶ if ( nodepath != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodepath != NULL ) { 14 10 24
5314 14 ▶ if ( self->type == XML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( self->type == XML_DOCUMENT_NODE 4 10 14
5315 4 ▶ || self->type == XML_HTML_DOCUMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_HTML_DOCUMENT_NODE 4 0 4
5316 4 ▶ || self->type == XML_DOCB_DOCUMENT_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
|| self->type == XML_DOCB_DOCUMENT_NODE ) { 0 4 4
5317 10 refNode = xmlDocGetRootElement( self->doc );
5318 }
5319 14 ▶ if (SvOK(xpath_context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(xpath_context)) { 2 12 14
5320 2 child_ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(xpath_context)));
5321 2 ▶ if ( child_ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( child_ctxt == NULL ) { 0 2 2
5322 0 croak("XPathContext: missing xpath context\n");
5323 }
5324 } else {
5325 12 xpath_context = NULL;
5326 12 child_ctxt = xmlXPathNewContext(self->doc);
5327 }
5328 14 ▶ if (!child_ctxt) {
Branch: 1 branch
BranchTrueFalseTotal
if (!child_ctxt) { 0 14 14
5329 0 ▶ if ( nodepath != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodepath != NULL ) { 0 0 0
5330 0 xmlFree( nodepath );
5331 }
5332 0 croak("Failed to create xpath context");
5333 }
5334  
5335 14 child_ctxt->node = self;
5336 14 LibXML_configure_namespaces(child_ctxt);
5337  
5338 14 xpath_res = xmlXPathEval(nodepath, child_ctxt);
5339 14 ▶ if (child_ctxt->namespaces != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_ctxt->namespaces != NULL) { 13 1 14
5340 13 xmlFree( child_ctxt->namespaces );
5341 13 child_ctxt->namespaces = NULL;
5342 }
5343 14 ▶ if (!xpath_context) xmlXPathFreeContext(child_ctxt);
Branch: 1 branch
BranchTrueFalseTotal
if (!xpath_context) xmlXPathFreeContext(child_ctxt); 12 2 14
5344 14 ▶ if ( nodepath != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodepath != NULL ) { 14 0 14
5345 14 xmlFree( nodepath );
5346 }
5347  
5348 14 ▶ if (xpath_res == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (xpath_res == NULL) { 0 14 14
5349 0 croak("2 Failed to compile xpath expression");
5350 }
5351  
5352 14 nodelist = xpath_res->nodesetval;
5353 14 ▶ if ( nodelist == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist == NULL ) { 0 14 14
5354 0 xmlXPathFreeObject(xpath_res);
5355 0 croak( "cannot canonize empty nodeset!" );
5356 }
5357 }
5358  
5359 24 INIT_ERROR_HANDLER;
5360  
5361 24 xmlC14NDocDumpMemory( self->doc,
5362 nodelist,
5363 exclusive, (xmlChar **) inc_prefix_list,
5364 comments,
5365 &result );
5366  
5367 24 ▶ if ( xpath_res ) xmlXPathFreeObject(xpath_res);
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath_res ) xmlXPathFreeObject(xpath_res); 14 10 24
5368 24 CLEANUP_ERROR_HANDLER;
5369 24 REPORT_ERROR(0);
5370  
5371 24 ▶ if (result == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (result == NULL) { 0 24 24
5372 0 croak("Failed to convert doc to string in doc->toStringC14N");
5373 } else {
5374 24 RETVAL = C2Sv( result, NULL );
5375 24 xmlFree(result);
5376 }
5377 OUTPUT:
5378 RETVAL
5379  
5380 SV*
5381 string_value ( self, useDomEncoding = &PL_sv_undef )
5382 xmlNodePtr self
5383 SV * useDomEncoding
5384 ALIAS:
5385 to_literal = 1
5386 textContent = 2
5387 PREINIT:
5388 100 xmlChar * string = NULL;
5389 CODE:
5390 PERL_UNUSED_VAR(ix);
5391 /* we can't just return a string, because of UTF8! */
5392 100 string = xmlXPathCastNodeToString(self);
5393 100 ▶ if ( SvTRUE(useDomEncoding) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( SvTRUE(useDomEncoding) ) { 1 99 100
5394 1 RETVAL = nodeC2Sv(string,
5395 self);
5396 }
5397 else {
5398 99 RETVAL = C2Sv(string,
5399 NULL);
5400 }
5401 100 xmlFree(string);
5402 OUTPUT:
5403 RETVAL
5404  
5405 double
5406 to_number ( self )
5407 xmlNodePtr self
5408 CODE:
5409 0 RETVAL = xmlXPathCastNodeToNumber(self);
5410 OUTPUT:
5411 RETVAL
5412  
5413  
5414 void
5415 _find( pnode, pxpath, to_bool )
5416 SV* pnode
5417 SV * pxpath
5418 int to_bool
5419 PREINIT:
5420 54 xmlNodePtr node = PmmSvNode(pnode);
5421 54 ProxyNodePtr owner = NULL;
5422 54 xmlXPathObjectPtr found = NULL;
5423 54 xmlNodeSetPtr nodelist = NULL;
5424 54 xmlChar * xpath = NULL;
5425 54 xmlXPathCompExprPtr comp = NULL;
5426 54 PREINIT_SAVED_ERROR
5427 INIT:
5428 54 ▶ if ( node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node == NULL ) { 0 54 54
5429 0 croak( "lost node" );
5430 }
5431 54 ▶ if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) { 3 51 54
if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) { 3 0 3
5432 3 comp = INT2PTR(xmlXPathCompExprPtr,SvIV((SV*)SvRV( pxpath )));
5433 3 ▶ if (!comp) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!comp) XSRETURN_UNDEF; 0 3 3
5434 } else {
5435 51 xpath = nodeSv2C(pxpath, node);
5436 51 ▶ if ( !(xpath && xmlStrlen(xpath)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !(xpath && xmlStrlen(xpath)) ) { 51 0 51
if ( !(xpath && xmlStrlen(xpath)) ) { 0 51 51
5437 xs_warn( "bad xpath\n" );
5438 0 ▶ if ( xpath )
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath ) 0 0 0
5439 0 xmlFree(xpath);
5440 0 croak( "empty XPath found" );
5441 XSRETURN_UNDEF;
5442 }
5443 }
5444 PPCODE:
5445 54 INIT_ERROR_HANDLER;
5446 54 ▶ if (comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (comp) { 3 51 54
5447 3 found = domXPathCompFind( node, comp, to_bool );
5448 } else {
5449 51 found = domXPathFind( node, xpath, to_bool );
5450 51 xmlFree( xpath );
5451 }
5452 54 CLEANUP_ERROR_HANDLER;
5453 54 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 42 12 54
5454 42 REPORT_ERROR(1);
5455 42 switch (found->type) {
5456 25 case XPATH_NODESET:
5457 /* return as a NodeList */
5458 /* access ->nodesetval */
5459 25 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0))); 0 25 25
5460 25 nodelist = found->nodesetval;
5461 25 ▶ if ( nodelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist ) { 25 0 25
5462 25 ▶ if ( nodelist->nodeNr > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist->nodeNr > 0 ) { 25 0 25
5463 int i;
5464 25 const char * cls = "XML::LibXML::Node";
5465 xmlNodePtr tnode;
5466 SV * element;
5467 25 int l = nodelist->nodeNr;
5468  
5469 25 ▶ owner = PmmOWNERPO(SvPROXYNODE(pnode));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(SvPROXYNODE(pnode)); 25 0 25
owner = PmmOWNERPO(SvPROXYNODE(pnode)); 1 24 25
5470 65 ▶ for( i=0 ; i < l; i++){
Branch: 1 branch
BranchTrueFalseTotal
for( i=0 ; i < l; i++){ 40 25 65
5471 /* we have to create a new instance of an
5472 * objectptr. and then
5473 * place the current node into the new
5474 * object. afterwards we can
5475 * push the object to the array!
5476 */
5477 40 tnode = nodelist->nodeTab[i];
5478  
5479 /* let's be paranoid */
5480 40 ▶ if (tnode->type == XML_NAMESPACE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->type == XML_NAMESPACE_DECL) { 0 40 40
5481 0 xmlNsPtr newns = xmlCopyNamespace((xmlNsPtr)tnode);
5482 0 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 0 0 0
5483 0 element = NEWSV(0,0);
5484 0 cls = PmmNodeTypeName( tnode );
5485 0 element = sv_setref_pv( element,
5486 (const char *)cls,
5487 (void*)newns
5488 );
5489 }
5490 else {
5491 0 continue;
5492 }
5493 }
5494 else {
5495 40 element = PmmNodeToSv(tnode, owner);
5496 }
5497  
5498 40 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 40 40
5499 }
5500 }
5501 25 xmlXPathFreeNodeSet( found->nodesetval );
5502 25 found->nodesetval = NULL;
5503 }
5504 25 break;
5505 12 case XPATH_BOOLEAN:
5506 /* return as a Boolean */
5507 /* access ->boolval */
5508 12 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0))); 0 12 12
5509 12 ▶ XPUSHs(sv_2mortal(newSViv(found->boolval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(found->boolval))); 0 12 12
5510 12 break;
5511 2 case XPATH_NUMBER:
5512 /* return as a Number */
5513 /* access ->floatval */
5514 2 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0))); 0 2 2
5515 2 ▶ XPUSHs(sv_2mortal(newSVnv(found->floatval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVnv(found->floatval))); 0 2 2
5516 2 break;
5517 3 case XPATH_STRING:
5518 /* access ->stringval */
5519 /* return as a Literal */
5520 3 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0))); 0 3 3
5521 3 ▶ XPUSHs(sv_2mortal(C2Sv(found->stringval, NULL)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(found->stringval, NULL))); 0 3 3
5522 3 break;
5523 0 default:
5524 0 croak("Unknown XPath return type");
5525 }
5526 42 xmlXPathFreeObject(found);
5527 } else {
5528 12 REPORT_ERROR(0);
5529 }
5530  
5531 void
5532 _findnodes( pnode, perl_xpath )
5533 SV* pnode
5534 SV * perl_xpath
5535 PREINIT:
5536 95 xmlNodePtr node = PmmSvNode(pnode);
5537 95 ProxyNodePtr owner = NULL;
5538 95 xmlNodeSetPtr nodelist = NULL;
5539 95 SV * element = NULL ;
5540 95 xmlChar * xpath = NULL ;
5541 95 xmlXPathCompExprPtr comp = NULL;
5542 95 PREINIT_SAVED_ERROR
5543 INIT:
5544 95 ▶ if ( node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node == NULL ) { 0 95 95
5545 0 ▶ if ( xpath )
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath ) 0 0 0
5546 0 xmlFree(xpath);
5547 0 croak( "lost node" );
5548 }
5549 95 ▶ if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) { 3 92 95
if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) { 3 0 3
5550 3 comp = INT2PTR(xmlXPathCompExprPtr,SvIV((SV*)SvRV( perl_xpath )));
5551 3 ▶ if (!comp) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!comp) XSRETURN_UNDEF; 0 3 3
5552 } else {
5553 92 xpath = nodeSv2C(perl_xpath, node);
5554 92 ▶ if ( !(xpath && xmlStrlen(xpath)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !(xpath && xmlStrlen(xpath)) ) { 92 0 92
if ( !(xpath && xmlStrlen(xpath)) ) { 0 92 92
5555 xs_warn( "bad xpath\n" );
5556 0 ▶ if ( xpath )
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath ) 0 0 0
5557 0 xmlFree(xpath);
5558 0 croak( "empty XPath found" );
5559 XSRETURN_UNDEF;
5560 }
5561 }
5562 PPCODE:
5563 95 INIT_ERROR_HANDLER;
5564 95 ▶ if (comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (comp) { 3 92 95
5565 3 nodelist = domXPathCompSelect( node, comp );
5566 } else {
5567 92 nodelist = domXPathSelect( node, xpath );
5568 92 xmlFree(xpath);
5569 }
5570 95 CLEANUP_ERROR_HANDLER;
5571  
5572 95 ▶ if ( nodelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist ) { 87 8 95
5573 87 REPORT_ERROR(1);
5574 87 ▶ if ( nodelist->nodeNr > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist->nodeNr > 0 ) { 81 6 87
5575 int i;
5576 81 int len = nodelist->nodeNr;
5577 81 const char * cls = "XML::LibXML::Node";
5578 xmlNodePtr tnode;
5579 81 ▶ owner = PmmOWNERPO(SvPROXYNODE(pnode));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(SvPROXYNODE(pnode)); 81 0 81
owner = PmmOWNERPO(SvPROXYNODE(pnode)); 22 59 81
5580  
5581 6280 ▶ for(i=0 ; i < len; i++){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0 ; i < len; i++){ 6199 81 6280
5582 /* we have to create a new instance of an objectptr.
5583 * and then place the current node into the new object.
5584 * afterwards we can push the object to the array!
5585 */
5586 6199 element = NULL;
5587 6199 tnode = nodelist->nodeTab[i];
5588 6199 ▶ if (tnode->type == XML_NAMESPACE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->type == XML_NAMESPACE_DECL) { 3 6196 6199
5589 3 xmlNsPtr newns = xmlCopyNamespace((xmlNsPtr)tnode);
5590 3 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 3 0 3
5591 3 element = NEWSV(0,0);
5592 3 cls = PmmNodeTypeName( tnode );
5593 3 element = sv_setref_pv( element,
5594 (const char *)cls,
5595 newns
5596 );
5597 }
5598 else {
5599 0 continue;
5600 }
5601 }
5602 else {
5603 6196 element = PmmNodeToSv(tnode, owner);
5604 }
5605  
5606 6199 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 6199 6199
5607 }
5608 }
5609 87 xmlXPathFreeNodeSet( nodelist );
5610 } else {
5611 8 REPORT_ERROR(0);
5612 }
5613  
5614 void
5615 getNamespaces( pnode )
5616 SV * pnode
5617 ALIAS:
5618 namespaces = 1
5619 PREINIT:
5620 xmlNodePtr node;
5621 37 xmlNsPtr ns = NULL;
5622 37 xmlNsPtr newns = NULL;
5623 37 SV* element = &PL_sv_undef;
5624 37 const char * class = "XML::LibXML::Namespace";
5625 INIT:
5626 PERL_UNUSED_VAR(ix);
5627 37 node = PmmSvNode(pnode);
5628 37 ▶ if ( node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node == NULL ) { 0 37 37
5629 0 croak( "lost node" );
5630 }
5631 PPCODE:
5632 37 ▶ if (node->type == XML_ELEMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_ELEMENT_NODE) { 37 0 37
5633 37 ns = node->nsDef;
5634 42 ▶ while ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ns != NULL ) { 5 37 42
5635 5 ▶ if (ns->prefix != NULL || ns->href != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (ns->prefix != NULL || ns->href != NULL) { 2 3 5
if (ns->prefix != NULL || ns->href != NULL) { 2 0 2
5636 5 newns = xmlCopyNamespace(ns);
5637 5 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 5 0 5
5638 5 element = NEWSV(0,0);
5639 5 element = sv_setref_pv( element,
5640 (const char *)class,
5641 (void*)newns
5642 );
5643 5 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 5 5
5644 }
5645 }
5646 5 ns = ns->next;
5647 }
5648 }
5649  
5650 SV *
5651 getNamespace( node )
5652 xmlNodePtr node
5653 ALIAS:
5654 localNamespace = 1
5655 localNS = 2
5656 PREINIT:
5657 1 xmlNsPtr ns = NULL;
5658 1 xmlNsPtr newns = NULL;
5659 1 const char * class = "XML::LibXML::Namespace";
5660 CODE:
5661 PERL_UNUSED_VAR(ix);
5662 1 ▶ if ( node->type == XML_ELEMENT_NODE
Branch: 1 branch
BranchTrueFalseTotal
if ( node->type == XML_ELEMENT_NODE 0 1 1
5663 0 ▶ || node->type == XML_ATTRIBUTE_NODE
Branch: 1 branch
BranchTrueFalseTotal
|| node->type == XML_ATTRIBUTE_NODE 0 0 0
5664 0 ▶ || node->type == XML_PI_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
|| node->type == XML_PI_NODE ) { 0 0 0
5665 1 ns = node->ns;
5666 1 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 1 0 1
5667 1 newns = xmlCopyNamespace(ns);
5668 1 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 1 0 1
5669 1 RETVAL = NEWSV(0,0);
5670 1 RETVAL = sv_setref_pv( RETVAL,
5671 (const char *)class,
5672 (void*)newns
5673 );
5674 } else {
5675 0 XSRETURN_UNDEF;
5676 }
5677 }
5678 else {
5679 0 XSRETURN_UNDEF;
5680 }
5681 } else {
5682 0 XSRETURN_UNDEF;
5683 }
5684 OUTPUT:
5685 RETVAL
5686  
5687  
5688 SV *
5689 nodePath( self )
5690 xmlNodePtr self
5691 PREINIT:
5692 3 xmlChar * path = NULL;
5693 CODE:
5694 3 path = xmlGetNodePath( self );
5695 3 ▶ if ( path == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( path == NULL ) { 0 3 3
5696 0 croak( "cannot calculate path for the given node" );
5697 }
5698 3 RETVAL = C2Sv( path, NULL );
5699 3 xmlFree(path);
5700 OUTPUT:
5701 RETVAL
5702  
5703 int
5704 line_number( self )
5705 xmlNodePtr self
5706 CODE:
5707 5 ▶ RETVAL = xmlGetLineNo( self );
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = xmlGetLineNo( self ); 0 5 5
5708 OUTPUT:
5709 RETVAL
5710  
5711 MODULE = XML::LibXML PACKAGE = XML::LibXML::Element
5712  
5713 SV*
5714 new(CLASS, name )
5715 char * name
5716 PREINIT:
5717 xmlNodePtr newNode;
5718 13 ProxyNodePtr docfrag = NULL;
5719 CODE:
5720 13 docfrag = PmmNewFragment(NULL);
5721 13 newNode = xmlNewNode( NULL, (const xmlChar*)name );
5722 13 newNode->doc = NULL;
5723 13 xmlAddChild(PmmNODE(docfrag), newNode);
5724 13 RETVAL = PmmNodeToSv(newNode, docfrag );
5725 OUTPUT:
5726 RETVAL
5727  
5728 int
5729 _setNamespace(self, namespaceURI, namespacePrefix = &PL_sv_undef, flag = 1 )
5730 SV * self
5731 SV * namespaceURI
5732 SV * namespacePrefix
5733 int flag
5734 PREINIT:
5735 33 xmlNodePtr node = PmmSvNode(self);
5736 33 xmlChar * nsURI = nodeSv2C(namespaceURI,node);
5737 33 xmlChar * nsPrefix = NULL;
5738 33 ▶ xmlNsPtr ns = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNsPtr ns = NULL; 33 0 33
5739 INIT:
5740 33 ▶ if ( node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node == NULL ) { 0 33 33
5741 0 croak( "lost node" );
5742 }
5743 CODE:
5744 /* if ( !nsURI ){
5745 XSRETURN_UNDEF;
5746 } */
5747  
5748 33 nsPrefix = nodeSv2C(namespacePrefix, node);
5749 33 ▶ if ( xmlStrlen( nsPrefix ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrlen( nsPrefix ) == 0 ) { 1 32 33
5750 1 xmlFree(nsPrefix);
5751 1 nsPrefix = NULL;
5752 }
5753 33 ▶ if ( xmlStrlen( nsURI ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrlen( nsURI ) == 0 ) { 1 32 33
5754 1 xmlFree(nsURI);
5755 1 nsURI = NULL;
5756 }
5757 33 ▶ if ( nsPrefix == NULL && nsURI == NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsPrefix == NULL && nsURI == NULL ) { 1 32 33
if ( nsPrefix == NULL && nsURI == NULL ) { 1 0 1
5758 /* special case: empty namespace */
5759 2 ▶ if ( (ns = xmlSearchNs(node->doc, node, NULL)) &&
Branch: 1 branch
BranchTrueFalseTotal
if ( (ns = xmlSearchNs(node->doc, node, NULL)) && 0 1 1
5760 0 ▶ ( ns->href && xmlStrlen( ns->href ) != 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
( ns->href && xmlStrlen( ns->href ) != 0 ) ) { 0 0 0
( ns->href && xmlStrlen( ns->href ) != 0 ) ) { 0 0 0
5761 /* won't take it */
5762 0 RETVAL = 0;
5763 1 ▶ } else if ( flag ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( flag ) { 1 0 1
5764 /* no namespace */
5765 1 xmlSetNs(node, NULL);
5766 1 RETVAL = 1;
5767 } else {
5768 0 RETVAL = 0;
5769 }
5770 }
5771 32 ▶ else if ( flag && (ns = xmlSearchNs(node->doc, node, nsPrefix)) ) {
Branch: 2 branches
BranchTrueFalseTotal
else if ( flag && (ns = xmlSearchNs(node->doc, node, nsPrefix)) ) { 4 28 32
else if ( flag && (ns = xmlSearchNs(node->doc, node, nsPrefix)) ) { 1 3 4
5772 /* user just wants to set the namespace for the node */
5773 /* try to reuse an existing declaration for the prefix */
5774 2 ▶ if ( xmlStrEqual( ns->href, nsURI ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrEqual( ns->href, nsURI ) ) { 1 0 1
5775 1 RETVAL = 1;
5776 }
5777 0 ▶ else if ( (ns = xmlNewNs( node, nsURI, nsPrefix )) ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( (ns = xmlNewNs( node, nsURI, nsPrefix )) ) { 0 0 0
5778 0 RETVAL = 1;
5779 }
5780 else {
5781 0 RETVAL = 0;
5782 }
5783 }
5784 31 ▶ else if ( (ns = xmlNewNs( node, nsURI, nsPrefix )) )
Branch: 1 branch
BranchTrueFalseTotal
else if ( (ns = xmlNewNs( node, nsURI, nsPrefix )) ) 31 0 31
5785 31 RETVAL = 1;
5786 else
5787 0 RETVAL = 0;
5788  
5789 33 ▶ if ( flag && ns ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( flag && ns ) { 5 28 33
if ( flag && ns ) { 4 1 5
5790 4 xmlSetNs(node, ns);
5791 }
5792 33 ▶ if ( nsPrefix ) xmlFree(nsPrefix);
Branch: 1 branch
BranchTrueFalseTotal
if ( nsPrefix ) xmlFree(nsPrefix); 32 1 33
5793 33 ▶ if ( nsURI ) xmlFree(nsURI);
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) xmlFree(nsURI); 32 1 33
5794 OUTPUT:
5795 RETVAL
5796  
5797 int
5798 setNamespaceDeclURI( self, svprefix, newURI )
5799 xmlNodePtr self
5800 SV * svprefix
5801 SV * newURI
5802 PREINIT:
5803 15 xmlChar * prefix = NULL;
5804 15 ▶ xmlChar * nsURI = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlChar * nsURI = NULL; 15 0 15
5805 xmlNsPtr ns;
5806 CODE:
5807 15 RETVAL = 0;
5808 15 prefix = nodeSv2C( svprefix , self );
5809 15 nsURI = nodeSv2C( newURI , self );
5810 /* null empty values */
5811 15 ▶ if ( prefix && xmlStrlen(prefix) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( prefix && xmlStrlen(prefix) == 0) { 15 0 15
if ( prefix && xmlStrlen(prefix) == 0) { 3 12 15
5812 3 xmlFree( prefix );
5813 3 prefix = NULL;
5814 }
5815 15 ▶ if ( nsURI && xmlStrlen(nsURI) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) == 0) { 12 3 15
if ( nsURI && xmlStrlen(nsURI) == 0) { 0 12 12
5816 0 xmlFree( nsURI );
5817 0 nsURI = NULL;
5818 }
5819 15 ns = self->nsDef;
5820 28 ▶ while ( ns ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ns ) { 20 8 28
5821 39 ▶ if ((ns->prefix || ns->href ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ((ns->prefix || ns->href ) && 11 9 20
5822 19 ( xmlStrcmp( ns->prefix, prefix ) == 0 )) {
5823 7 ▶ if (ns->href) xmlFree((char*)ns->href);
Branch: 1 branch
BranchTrueFalseTotal
if (ns->href) xmlFree((char*)ns->href); 7 0 7
5824 7 ns->href = nsURI;
5825 7 ▶ if ( nsURI == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI == NULL ) { 3 4 7
5826 3 domRemoveNsRefs( self, ns );
5827 } else
5828 4 nsURI = NULL; /* do not free it */
5829 7 RETVAL = 1;
5830 7 break;
5831 } else {
5832 13 ns = ns->next;
5833 }
5834 }
5835 15 ▶ if ( prefix ) xmlFree( prefix );
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) xmlFree( prefix ); 12 3 15
5836 15 ▶ if ( nsURI ) xmlFree( nsURI );
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) xmlFree( nsURI ); 8 7 15
5837 OUTPUT:
5838 RETVAL
5839  
5840 int
5841 setNamespaceDeclPrefix( self, svprefix, newPrefix )
5842 xmlNodePtr self
5843 SV * svprefix
5844 SV * newPrefix
5845 PREINIT:
5846 6 xmlChar * prefix = NULL;
5847 6 ▶ xmlChar * nsPrefix = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlChar * nsPrefix = NULL; 6 0 6
5848 xmlNsPtr ns;
5849 CODE:
5850 6 RETVAL = 0;
5851 6 prefix = nodeSv2C( svprefix , self );
5852 6 nsPrefix = nodeSv2C( newPrefix , self );
5853 /* null empty values */
5854 6 ▶ if ( prefix != NULL && xmlStrlen(prefix) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 6 0 6
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 1 5 6
5855 1 xmlFree( prefix );
5856 1 prefix = NULL;
5857 }
5858 6 ▶ if ( nsPrefix != NULL && xmlStrlen(nsPrefix) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsPrefix != NULL && xmlStrlen(nsPrefix) == 0) { 5 1 6
if ( nsPrefix != NULL && xmlStrlen(nsPrefix) == 0) { 2 3 5
5859 2 xmlFree( nsPrefix );
5860 2 nsPrefix = NULL;
5861 }
5862 6 ▶ if ( xmlStrcmp( prefix, nsPrefix ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrcmp( prefix, nsPrefix ) == 0 ) { 0 6 6
5863 0 RETVAL = 1;
5864 } else {
5865 /* check that new prefix is not in scope */
5866 6 ns = xmlSearchNs( self->doc, self, nsPrefix );
5867 6 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 2 4 6
5868 2 ▶ if (nsPrefix != NULL) xmlFree( nsPrefix );
Branch: 1 branch
BranchTrueFalseTotal
if (nsPrefix != NULL) xmlFree( nsPrefix ); 1 1 2
5869 2 ▶ if (prefix != NULL) xmlFree( prefix );
Branch: 1 branch
BranchTrueFalseTotal
if (prefix != NULL) xmlFree( prefix ); 2 0 2
5870 2 croak("setNamespaceDeclPrefix: prefix '%s' is in use", ns->prefix);
5871 }
5872 /* lookup the declaration */
5873 4 ns = self->nsDef;
5874 7 ▶ while ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ns != NULL ) { 7 0 7
5875 13 ▶ if ((ns->prefix != NULL || ns->href != NULL) &&
Branch: 1 branch
BranchTrueFalseTotal
if ((ns->prefix != NULL || ns->href != NULL) && 3 4 7
5876 6 xmlStrcmp( ns->prefix, prefix ) == 0 ) {
5877 4 ▶ if ( ns->href == NULL && nsPrefix != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ns->href == NULL && nsPrefix != NULL ) { 1 3 4
if ( ns->href == NULL && nsPrefix != NULL ) { 0 1 1
5878 /* xmlns:foo="" - no go */
5879 0 ▶ if ( prefix != NULL) xmlFree(prefix);
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL) xmlFree(prefix); 0 0 0
5880 0 croak("setNamespaceDeclPrefix: cannot set non-empty prefix for empty namespace");
5881 }
5882 4 ▶ if ( ns->prefix != NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( ns->prefix != NULL ) 3 1 4
5883 3 xmlFree( (xmlChar*)ns->prefix );
5884 4 ns->prefix = nsPrefix;
5885 4 nsPrefix = NULL; /* do not free it */
5886 4 RETVAL = 1;
5887 4 break;
5888 } else {
5889 3 ns = ns->next;
5890 }
5891 }
5892 }
5893 4 ▶ if ( nsPrefix != NULL ) xmlFree(nsPrefix);
Branch: 1 branch
BranchTrueFalseTotal
if ( nsPrefix != NULL ) xmlFree(nsPrefix); 0 4 4
5894 4 ▶ if ( prefix != NULL) xmlFree(prefix);
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL) xmlFree(prefix); 3 1 4
5895 OUTPUT:
5896 RETVAL
5897  
5898  
5899 SV*
5900 _getNamespaceDeclURI( self, ns_prefix )
5901 xmlNodePtr self
5902 SV * ns_prefix
5903 PREINIT:
5904 xmlChar * prefix;
5905 xmlNsPtr ns;
5906 CODE:
5907 22 prefix = nodeSv2C(ns_prefix, self );
5908 22 ▶ if ( prefix != NULL && xmlStrlen(prefix) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 21 1 22
if ( prefix != NULL && xmlStrlen(prefix) == 0) { 3 18 21
5909 3 xmlFree( prefix );
5910 3 prefix = NULL;
5911 }
5912 22 RETVAL = &PL_sv_undef;
5913 22 ns = self->nsDef;
5914 33 ▶ while ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ns != NULL ) { 24 9 33
5915 48 ▶ if ( (ns->prefix != NULL || ns->href != NULL) &&
Branch: 1 branch
BranchTrueFalseTotal
if ( (ns->prefix != NULL || ns->href != NULL) && 8 16 24
5916 24 xmlStrcmp( ns->prefix, prefix ) == 0 ) {
5917 13 RETVAL = C2Sv(ns->href, NULL);
5918 13 break;
5919 } else {
5920 11 ns = ns->next;
5921 }
5922 }
5923 22 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 18 4 22
5924 18 xmlFree( prefix );
5925 }
5926  
5927 OUTPUT:
5928 RETVAL
5929  
5930 int
5931 hasAttribute( self, attr_name )
5932 xmlNodePtr self
5933 SV * attr_name
5934 PREINIT:
5935 xmlChar * name;
5936 CODE:
5937 16 name = nodeSv2C(attr_name, self );
5938 16 ▶ if ( ! name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ! name ) { 0 16 16
5939 0 XSRETURN_UNDEF;
5940 }
5941 16 ▶ if ( domGetAttrNode( self, name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( domGetAttrNode( self, name ) ) { 9 7 16
5942 9 RETVAL = 1;
5943 }
5944 else {
5945 7 RETVAL = 0;
5946 }
5947 16 xmlFree(name);
5948 OUTPUT:
5949 RETVAL
5950  
5951 int
5952 hasAttributeNS( self, namespaceURI, attr_name )
5953 xmlNodePtr self
5954 SV * namespaceURI
5955 SV * attr_name
5956 PREINIT:
5957 xmlChar * name;
5958 xmlChar * nsURI;
5959 xmlNodePtr attr;
5960 CODE:
5961 16 name = nodeSv2C(attr_name, self );
5962 16 nsURI = nodeSv2C(namespaceURI, self );
5963  
5964 16 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 16 16
5965 0 ▶ if ( nsURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI != NULL ) { 0 0 0
5966 0 xmlFree(nsURI);
5967 }
5968 0 XSRETURN_UNDEF;
5969 }
5970 16 ▶ if ( nsURI != NULL && xmlStrlen(nsURI) == 0 ){
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI != NULL && xmlStrlen(nsURI) == 0 ){ 14 2 16
if ( nsURI != NULL && xmlStrlen(nsURI) == 0 ){ 2 12 14
5971 2 xmlFree(nsURI);
5972 2 nsURI = NULL;
5973 }
5974 16 attr = (xmlNodePtr) xmlHasNsProp( self, name, nsURI );
5975 16 ▶ if ( attr && attr->type == XML_ATTRIBUTE_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( attr && attr->type == XML_ATTRIBUTE_NODE ) { 10 6 16
if ( attr && attr->type == XML_ATTRIBUTE_NODE ) { 8 2 10
5976 8 RETVAL = 1;
5977 }
5978 else {
5979 8 RETVAL = 0;
5980 }
5981  
5982 16 xmlFree(name);
5983 16 ▶ if ( nsURI != NULL ){
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI != NULL ){ 12 4 16
5984 12 xmlFree(nsURI);
5985 }
5986 OUTPUT:
5987 RETVAL
5988  
5989 SV*
5990 _getAttribute( self, attr_name, useDomEncoding = 0 )
5991 xmlNodePtr self
5992 SV * attr_name
5993 int useDomEncoding
5994 PREINIT:
5995 xmlChar * name;
5996 46 xmlChar * prefix = NULL;
5997 46 xmlChar * localname = NULL;
5998 46 xmlChar * ret = NULL;
5999 46 xmlNsPtr ns = NULL;
6000 CODE:
6001 46 name = nodeSv2C(attr_name, self );
6002 46 ▶ if( !name ) {
Branch: 1 branch
BranchTrueFalseTotal
if( !name ) { 0 46 46
6003 0 XSRETURN_UNDEF;
6004 }
6005  
6006 46 ret = xmlGetNoNsProp(self, name);
6007 46 ▶ if ( ret == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret == NULL ) { 7 39 46
6008 7 localname = xmlSplitQName2(name, &prefix);
6009 7 ▶ if ( localname != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname != NULL ) { 7 0 7
6010 7 ns = xmlSearchNs( self->doc, self, prefix );
6011 7 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 7 0 7
6012 7 ret = xmlGetNsProp(self, localname, ns->href);
6013 }
6014 7 ▶ if ( prefix != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL) { 7 0 7
6015 7 xmlFree( prefix );
6016 }
6017 7 xmlFree( localname );
6018 }
6019 }
6020 46 xmlFree(name);
6021 46 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 46 0 46
6022 46 ▶ if ( useDomEncoding ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( useDomEncoding ) { 9 37 46
6023 9 RETVAL = nodeC2Sv(ret, self);
6024 }
6025 else {
6026 37 RETVAL = C2Sv(ret, NULL);
6027 }
6028 46 xmlFree( ret );
6029 }
6030 else {
6031 0 XSRETURN_UNDEF;
6032 }
6033  
6034 OUTPUT:
6035 RETVAL
6036  
6037 void
6038 _setAttribute( self, attr_name, attr_value )
6039 xmlNodePtr self
6040 SV * attr_name
6041 SV * attr_value
6042 PREINIT:
6043 28 xmlChar * name = NULL;
6044 28 xmlChar * value = NULL;
6045 #if LIBXML_VERSION < 20621
6046 xmlChar * prefix = NULL;
6047 xmlChar * localname = NULL;
6048 #endif
6049 CODE:
6050 28 name = nodeSv2C(attr_name, self );
6051  
6052 28 ▶ if ( !LibXML_test_node_name(name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name(name) ) { 4 24 28
6053 4 xmlFree(name);
6054 4 croak( "bad name" );
6055 }
6056 24 value = nodeSv2C(attr_value, self );
6057 #if LIBXML_VERSION >= 20621
6058 /*
6059 * For libxml2-2.6.21 and later we can use just xmlSetProp
6060 */
6061 24 xmlSetProp(self,name,value);
6062 #else
6063 /*
6064 * but xmlSetProp does not work correctly for older libxml2 versions
6065 * The following is copied from libxml2 source
6066 * with xmlSplitQName3 replaced by xmlSplitQName2 for compatibility
6067 * with older libxml2 versions
6068 */
6069 localname = xmlSplitQName2(name, &prefix);
6070 if (localname != NULL) {
6071 xmlNsPtr ns;
6072 ns = xmlSearchNs(self->doc, self, prefix);
6073 if (prefix != NULL)
6074 xmlFree(prefix);
6075 if (ns != NULL)
6076 xmlSetNsProp(self, ns, localname, value);
6077 else
6078 xmlSetNsProp(self, NULL, name, value);
6079 xmlFree(localname);
6080 } else {
6081 xmlSetNsProp(self, NULL, name, value);
6082 }
6083 #endif
6084 24 xmlFree(name);
6085 24 xmlFree(value);
6086  
6087  
6088 void
6089 removeAttribute( self, attr_name )
6090 xmlNodePtr self
6091 SV * attr_name
6092 PREINIT:
6093 xmlChar * name;
6094 4 xmlAttrPtr xattr = NULL;
6095 CODE:
6096 4 name = nodeSv2C(attr_name, self );
6097 4 ▶ if ( name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name ) { 4 0 4
6098 4 xattr = domGetAttrNode( self, name );
6099  
6100 4 ▶ if ( xattr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xattr ) { 4 0 4
6101 4 xmlUnlinkNode((xmlNodePtr)xattr);
6102 4 ▶ if ( xattr->_private ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xattr->_private ) { 1 3 4
6103 1 PmmFixOwner((ProxyNodePtr)xattr->_private, NULL);
6104 }
6105 else {
6106 3 xmlFreeProp(xattr);
6107 }
6108 }
6109 4 xmlFree(name);
6110 }
6111  
6112 SV*
6113 getAttributeNode( self, attr_name )
6114 xmlNodePtr self
6115 SV * attr_name
6116 PREINIT:
6117 xmlChar * name;
6118 45 xmlAttrPtr ret = NULL;
6119 CODE:
6120 45 name = nodeSv2C(attr_name, self );
6121 45 ▶ if ( !name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !name ) { 0 45 45
6122 0 XSRETURN_UNDEF;
6123 }
6124  
6125 45 ret = domGetAttrNode( self, name );
6126 45 xmlFree(name);
6127 45 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 30 15 45
6128 30 RETVAL = PmmNodeToSv( (xmlNodePtr)ret,
6129 30 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 30 0 30
PmmOWNERPO(PmmPROXYNODE(self)) ); 30 0 30
6130 }
6131 else {
6132 15 XSRETURN_UNDEF;
6133 }
6134 OUTPUT:
6135 RETVAL
6136  
6137 SV *
6138 setAttributeNode( self, attr_node )
6139 xmlNodePtr self
6140 SV * attr_node
6141 PREINIT:
6142 1 xmlAttrPtr attr = (xmlAttrPtr)PmmSvNode( attr_node );
6143 1 xmlAttrPtr ret = NULL;
6144 INIT:
6145 1 ▶ if ( attr == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr == NULL ) { 0 1 1
6146 0 croak( "lost attribute" );
6147 }
6148 CODE:
6149 1 ▶ if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) { 1 0 1
if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) { 0 1 1
6150 0 XSRETURN_UNDEF;
6151 }
6152 1 ▶ if ( attr->doc != self->doc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->doc != self->doc ) { 0 1 1
6153 0 domImportNode( self->doc, (xmlNodePtr)attr, 1, 1);
6154 }
6155 1 ret = domGetAttrNode( self, attr->name );
6156 1 ▶ if ( ret != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != NULL ) { 0 1 1
6157 0 ▶ if ( ret != attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != attr ) { 0 0 0
6158 0 xmlReplaceNode( (xmlNodePtr)ret, (xmlNodePtr)attr );
6159 }
6160 else {
6161 0 XSRETURN_UNDEF;
6162 }
6163 }
6164 else {
6165 1 xmlAddChild( self, (xmlNodePtr)attr );
6166 }
6167  
6168 1 ▶ if ( attr->_private != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->_private != NULL ) { 1 0 1
6169 1 PmmFixOwner( SvPROXYNODE(attr_node), PmmPROXYNODE(self) );
6170 }
6171  
6172 1 ▶ if ( ret == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret == NULL ) { 1 0 1
6173 1 XSRETURN_UNDEF;
6174 }
6175  
6176 0 RETVAL = PmmNodeToSv( (xmlNodePtr)ret, NULL );
6177 0 PmmFixOwner( SvPROXYNODE(RETVAL), NULL );
6178 OUTPUT:
6179 RETVAL
6180  
6181 SV *
6182 _getAttributeNS( self, namespaceURI, attr_name, useDomEncoding = 0 )
6183 xmlNodePtr self
6184 SV * namespaceURI
6185 SV * attr_name
6186 int useDomEncoding
6187 PREINIT:
6188 xmlChar * name;
6189 xmlChar * nsURI;
6190 22 xmlChar * ret = NULL;
6191 CODE:
6192 22 name = nodeSv2C( attr_name, self );
6193 22 nsURI = nodeSv2C( namespaceURI, self );
6194 22 ▶ if ( !name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !name ) { 0 22 22
6195 0 xmlFree(nsURI);
6196 0 XSRETURN_UNDEF;
6197 }
6198 22 ▶ if ( nsURI && xmlStrlen(nsURI) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) ) { 21 1 22
if ( nsURI && xmlStrlen(nsURI) ) { 20 1 21
6199 20 ret = xmlGetNsProp( self, name, nsURI );
6200 }
6201 else {
6202 2 ret = xmlGetProp( self, name );
6203 }
6204  
6205 22 xmlFree( name );
6206 22 ▶ if ( nsURI ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) { 21 1 22
6207 21 xmlFree( nsURI );
6208 }
6209 22 ▶ if ( ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret ) { 22 0 22
6210 22 ▶ if (useDomEncoding) {
Branch: 1 branch
BranchTrueFalseTotal
if (useDomEncoding) { 0 22 22
6211 0 RETVAL = nodeC2Sv( ret, self );
6212 } else {
6213 22 RETVAL = C2Sv( ret, NULL );
6214 }
6215 22 xmlFree( ret );
6216 }
6217 else {
6218 0 XSRETURN_UNDEF;
6219 }
6220 OUTPUT:
6221 RETVAL
6222  
6223 void
6224 _setAttributeNS( self, namespaceURI, attr_name, attr_value )
6225 xmlNodePtr self
6226 SV * namespaceURI
6227 SV * attr_name
6228 SV * attr_value
6229 PREINIT:
6230 xmlChar * nsURI;
6231 48 xmlChar * name = NULL;
6232 48 xmlChar * value = NULL;
6233 48 xmlNsPtr ns = NULL;
6234 48 xmlChar * localname = NULL;
6235 48 xmlChar * prefix = NULL;
6236 48 xmlNsPtr * all_ns = NULL;
6237 int i;
6238 INIT:
6239 48 name = nodeSv2C( attr_name, self );
6240  
6241 48 ▶ if ( !LibXML_test_node_name(name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !LibXML_test_node_name(name) ) { 3 45 48
6242 3 xmlFree(name);
6243 3 croak( "bad name" );
6244 }
6245  
6246 45 nsURI = nodeSv2C( namespaceURI, self );
6247 45 localname = xmlSplitQName2(name, &prefix);
6248 45 ▶ if ( localname ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname ) { 21 24 45
6249 21 xmlFree( name );
6250 21 name = localname;
6251 }
6252 CODE:
6253 45 value = nodeSv2C( attr_value, self );
6254  
6255 45 ▶ if ( nsURI && xmlStrlen(nsURI) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) ) { 44 1 45
if ( nsURI && xmlStrlen(nsURI) ) { 24 20 44
6256 xs_warn( "found uri" );
6257  
6258 24 ns = xmlSearchNsByHref( self->doc, self, nsURI );
6259  
6260 /*
6261 * check for any prefixed namespaces occluded by a default namespace
6262 * because xmlSearchNsByHref will return default namespaces unless
6263 * you are searching on an attribute node, which may not exist yet
6264 */
6265 24 ▶ if ( ns && !ns->prefix )
Branch: 2 branches
BranchTrueFalseTotal
if ( ns && !ns->prefix ) 20 4 24
if ( ns && !ns->prefix ) 4 16 20
6266 {
6267 4 all_ns = xmlGetNsList(self->doc, self);
6268 4 ▶ if ( all_ns )
Branch: 1 branch
BranchTrueFalseTotal
if ( all_ns ) 4 0 4
6269 {
6270 4 i = 0;
6271 4 ns = all_ns[i];
6272 14 ▶ while ( ns )
Branch: 1 branch
BranchTrueFalseTotal
while ( ns ) 13 1 14
6273 {
6274 13 ▶ if ( ns->prefix && xmlStrEqual(ns->href, nsURI) )
Branch: 2 branches
BranchTrueFalseTotal
if ( ns->prefix && xmlStrEqual(ns->href, nsURI) ) 5 8 13
if ( ns->prefix && xmlStrEqual(ns->href, nsURI) ) 3 2 5
6275 {
6276 3 break;
6277 }
6278 10 ns = all_ns[i++];
6279 }
6280 4 xmlFree(all_ns);
6281 }
6282 }
6283  
6284 24 ▶ if ( !ns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !ns ) { 5 19 24
6285 /* create new ns */
6286 5 ▶ if ( prefix && xmlStrlen( prefix ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( prefix && xmlStrlen( prefix ) ) { 5 0 5
if ( prefix && xmlStrlen( prefix ) ) { 5 0 5
6287 5 ns = xmlNewNs(self, nsURI , prefix);
6288 }
6289 else {
6290 0 ns = NULL;
6291 }
6292 }
6293 }
6294  
6295 45 ▶ if ( nsURI && xmlStrlen(nsURI) && !ns ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) && !ns ) { 44 1 45
if ( nsURI && xmlStrlen(nsURI) && !ns ) { 24 20 44
if ( nsURI && xmlStrlen(nsURI) && !ns ) { 0 24 24
6296 0 ▶ if ( prefix ) xmlFree( prefix );
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) xmlFree( prefix ); 0 0 0
6297 0 ▶ if ( nsURI ) xmlFree( nsURI );
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) xmlFree( nsURI ); 0 0 0
6298 0 xmlFree( name );
6299 0 xmlFree( value );
6300 0 croak( "bad ns attribute!" );
6301 }
6302 else {
6303 /* warn( "set attribute %s->%s", name, value ); */
6304 45 xmlSetNsProp( self, ns, name, value );
6305 }
6306  
6307 45 ▶ if ( prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) { 21 24 45
6308 21 xmlFree( prefix );
6309 }
6310 45 ▶ if ( nsURI ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) { 44 1 45
6311 44 xmlFree( nsURI );
6312 }
6313 45 xmlFree( name );
6314 45 xmlFree( value );
6315  
6316 void
6317 removeAttributeNS( self, namespaceURI, attr_name )
6318 xmlNodePtr self
6319 SV * namespaceURI
6320 SV * attr_name
6321 PREINIT:
6322 xmlChar * nsURI;
6323 3 xmlChar * name = NULL;
6324 3 xmlAttrPtr xattr = NULL;
6325 CODE:
6326 3 nsURI = nodeSv2C( namespaceURI, self );
6327 3 name = nodeSv2C( attr_name, self );
6328 3 ▶ if ( ! name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ! name ) { 0 3 3
6329 0 xmlFree(nsURI);
6330 0 XSRETURN_UNDEF;
6331 }
6332  
6333 3 ▶ if ( nsURI && xmlStrlen(nsURI) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) ) { 3 0 3
if ( nsURI && xmlStrlen(nsURI) ) { 2 1 3
6334 2 xattr = xmlHasNsProp( self, name, nsURI );
6335 }
6336 else {
6337 1 xattr = xmlHasNsProp( self, name, NULL );
6338 }
6339 3 ▶ if ( xattr && xattr->type == XML_ATTRIBUTE_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( xattr && xattr->type == XML_ATTRIBUTE_NODE ) { 3 0 3
if ( xattr && xattr->type == XML_ATTRIBUTE_NODE ) { 3 0 3
6340 3 xmlUnlinkNode((xmlNodePtr)xattr);
6341 3 ▶ if ( xattr->_private ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xattr->_private ) { 2 1 3
6342 2 PmmFixOwner((ProxyNodePtr)xattr->_private, NULL);
6343 }
6344 else {
6345 1 xmlFreeProp(xattr);
6346 }
6347 }
6348 3 xmlFree(nsURI);
6349 3 xmlFree( name );
6350  
6351  
6352 SV*
6353 getAttributeNodeNS( self,namespaceURI, attr_name )
6354 xmlNodePtr self
6355 SV * namespaceURI
6356 SV * attr_name
6357 PREINIT:
6358 xmlChar * nsURI;
6359 xmlChar * name;
6360 33 xmlAttrPtr ret = NULL;
6361 CODE:
6362 33 nsURI = nodeSv2C(namespaceURI, self );
6363 33 name = nodeSv2C(attr_name, self );
6364 33 ▶ if ( !name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !name ) { 0 33 33
6365 0 xmlFree(nsURI);
6366 0 XSRETURN_UNDEF;
6367 }
6368 33 ▶ if ( nsURI && xmlStrlen(nsURI) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen(nsURI) ) { 20 13 33
if ( nsURI && xmlStrlen(nsURI) ) { 20 0 20
6369 20 ret = xmlHasNsProp( self, name, nsURI );
6370 }
6371 else {
6372 13 ret = xmlHasNsProp( self, name, NULL );
6373 }
6374 33 xmlFree(name);
6375 33 ▶ if ( nsURI ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI ) { 20 13 33
6376 20 xmlFree(nsURI);
6377 }
6378 33 ▶ if ( ret &&
Branch: 1 branch
BranchTrueFalseTotal
if ( ret && 18 15 33
6379 18 ▶ ret->type == XML_ATTRIBUTE_NODE /* we don't want fixed attribute decls */
Branch: 1 branch
BranchTrueFalseTotal
ret->type == XML_ATTRIBUTE_NODE /* we don't want fixed attribute decls */ 12 6 18
6380 ) {
6381 12 RETVAL = PmmNodeToSv( (xmlNodePtr)ret,
6382 12 ▶ PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
PmmOWNERPO(PmmPROXYNODE(self)) ); 12 0 12
PmmOWNERPO(PmmPROXYNODE(self)) ); 12 0 12
6383 }
6384 else {
6385 /* warn("no prop\n"); */
6386 21 XSRETURN_UNDEF;
6387 }
6388 OUTPUT:
6389 RETVAL
6390  
6391 SV *
6392 setAttributeNodeNS( self, attr_node )
6393 xmlNodePtr self
6394 SV * attr_node
6395 PREINIT:
6396 4 xmlAttrPtr attr = (xmlAttrPtr)PmmSvNode( attr_node );
6397 4 xmlNsPtr ns = NULL;
6398 4 xmlAttrPtr ret = NULL;
6399 INIT:
6400 4 ▶ if ( attr == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr == NULL ) { 0 4 4
6401 0 croak( "lost attribute node" );
6402 }
6403 CODE:
6404 4 ▶ if ( attr->type != XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->type != XML_ATTRIBUTE_NODE ) { 0 4 4
6405 0 XSRETURN_UNDEF;
6406 }
6407  
6408 4 ▶ if ( attr->doc != self->doc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->doc != self->doc ) { 1 3 4
6409 1 domImportNode( self->doc, (xmlNodePtr)attr, 1,1);
6410 }
6411  
6412  
6413 4 ns = attr->ns;
6414 4 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 4 0 4
6415 4 ret = xmlHasNsProp( self, ns->href, attr->name );
6416 }
6417 else {
6418 0 ret = xmlHasNsProp( self, NULL, attr->name );
6419 }
6420  
6421 4 ▶ if ( ret && ret->type == XML_ATTRIBUTE_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ret && ret->type == XML_ATTRIBUTE_NODE ) { 0 4 4
if ( ret && ret->type == XML_ATTRIBUTE_NODE ) { 0 0 0
6422 0 ▶ if ( ret != attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != attr ) { 0 0 0
6423 0 xmlReplaceNode( (xmlNodePtr)ret, (xmlNodePtr)attr );
6424 }
6425 else {
6426 0 XSRETURN_UNDEF;
6427 }
6428 }
6429 else {
6430 4 xmlAddChild( self, (xmlNodePtr)attr );
6431 4 xmlReconciliateNs(self->doc, self);
6432 }
6433 4 ▶ if ( attr->_private != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->_private != NULL ) { 4 0 4
6434 4 PmmFixOwner( SvPROXYNODE(attr_node), PmmPROXYNODE(self) );
6435 }
6436 4 ▶ if ( ret != NULL && ret->type == XML_ATTRIBUTE_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ret != NULL && ret->type == XML_ATTRIBUTE_NODE ) { 0 4 4
if ( ret != NULL && ret->type == XML_ATTRIBUTE_NODE ) { 0 0 0
6437 0 RETVAL = PmmNodeToSv( (xmlNodePtr)ret, NULL );
6438 0 PmmFixOwner( SvPROXYNODE(RETVAL), NULL );
6439 } else {
6440 4 XSRETURN_UNDEF;
6441 }
6442 OUTPUT:
6443 RETVAL
6444  
6445 SV *
6446 removeAttributeNode( self, attr_node )
6447 xmlNodePtr self
6448 SV * attr_node
6449 PREINIT:
6450 3 xmlAttrPtr attr = (xmlAttrPtr)PmmSvNode( attr_node );
6451 xmlAttrPtr ret;
6452 INIT:
6453 3 ▶ if ( attr == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr == NULL ) { 0 3 3
6454 0 croak( "lost attribute node" );
6455 }
6456 CODE:
6457 3 ▶ if ( attr->type != XML_ATTRIBUTE_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->type != XML_ATTRIBUTE_NODE ) { 0 3 3
6458 0 XSRETURN_UNDEF;
6459 }
6460 3 ▶ if ( attr->parent != self ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr->parent != self ) { 0 3 3
6461 0 XSRETURN_UNDEF;
6462 }
6463 3 ret = attr;
6464 3 xmlUnlinkNode( (xmlNodePtr)attr );
6465 3 RETVAL = PmmNodeToSv( (xmlNodePtr)ret, NULL );
6466 3 PmmFixOwner( SvPROXYNODE(RETVAL), NULL );
6467 OUTPUT:
6468 RETVAL
6469  
6470 void
6471 appendText( self, string )
6472 xmlNodePtr self
6473 SV * string
6474 ALIAS:
6475 appendTextNode = 1
6476 XML::LibXML::DocumentFragment::appendText = 2
6477 XML::LibXML::DocumentFragment::appendTextNode = 3
6478 PREINIT:
6479 88 xmlChar * content = NULL;
6480 INIT:
6481 PERL_UNUSED_VAR(ix);
6482 88 content = nodeSv2C( string, self );
6483 88 ▶ if ( content == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( content == NULL ) { 0 88 88
6484 0 XSRETURN_UNDEF;
6485 }
6486 88 ▶ if ( xmlStrlen(content) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrlen(content) == 0 ) { 0 88 88
6487 0 xmlFree( content );
6488 0 XSRETURN_UNDEF;
6489 }
6490 CODE:
6491 88 xmlNodeAddContent( self, content );
6492 88 xmlFree(content);
6493  
6494  
6495 void
6496 appendTextChild( self, strname, strcontent=&PL_sv_undef, nsURI=&PL_sv_undef )
6497 xmlNodePtr self
6498 SV * strname
6499 SV * strcontent
6500 SV * nsURI
6501 PREINIT:
6502 xmlChar * name;
6503 3 xmlChar * content = NULL;
6504 3 xmlChar * encstr = NULL;
6505 INIT:
6506 3 name = nodeSv2C( strname, self );
6507 3 ▶ if ( xmlStrlen(name) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrlen(name) == 0 ) { 0 3 3
6508 0 xmlFree(name);
6509 0 XSRETURN_UNDEF;
6510 }
6511 CODE:
6512 3 content = nodeSv2C(strcontent, self);
6513 3 ▶ if ( content && xmlStrlen( content ) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( content && xmlStrlen( content ) == 0 ) { 2 1 3
if ( content && xmlStrlen( content ) == 0 ) { 0 2 2
6514 0 xmlFree(content);
6515 0 content=NULL;
6516 }
6517 3 ▶ else if ( content ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( content ) { 2 1 3
6518 2 encstr = xmlEncodeEntitiesReentrant( self->doc, content );
6519 2 xmlFree(content);
6520 }
6521  
6522 3 xmlNewChild( self, NULL, name, encstr );
6523  
6524 3 ▶ if ( encstr )
Branch: 1 branch
BranchTrueFalseTotal
if ( encstr ) 2 1 3
6525 2 xmlFree(encstr);
6526 3 xmlFree(name);
6527  
6528 SV *
6529 addNewChild( self, namespaceURI, nodename )
6530 xmlNodePtr self
6531 SV * namespaceURI
6532 SV * nodename
6533 ALIAS:
6534 XML::LibXML::DocumentFragment::addNewChild = 1
6535 PREINIT:
6536 72 xmlChar * nsURI = NULL;
6537 72 xmlChar * name = NULL;
6538 72 xmlChar * localname = NULL;
6539 72 xmlChar * prefix = NULL;
6540 72 xmlNodePtr newNode = NULL;
6541 72 xmlNodePtr prev = NULL;
6542 72 xmlNsPtr ns = NULL;
6543 CODE:
6544 PERL_UNUSED_VAR(ix);
6545 72 name = nodeSv2C(nodename, self);
6546 72 ▶ if ( name && xmlStrlen( name ) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( name && xmlStrlen( name ) == 0 ) { 72 0 72
if ( name && xmlStrlen( name ) == 0 ) { 0 72 72
6547 0 xmlFree(name);
6548 0 XSRETURN_UNDEF;
6549 }
6550  
6551 72 nsURI = nodeSv2C(namespaceURI, self);
6552 72 ▶ if ( nsURI && xmlStrlen( nsURI ) == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( nsURI && xmlStrlen( nsURI ) == 0 ) { 72 0 72
if ( nsURI && xmlStrlen( nsURI ) == 0 ) { 50 22 72
6553 50 xmlFree(nsURI);
6554 50 nsURI=NULL;
6555 }
6556  
6557 72 ▶ if ( nsURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI != NULL ) { 22 50 72
6558 22 localname = xmlSplitQName2(name, &prefix);
6559 22 ns = xmlSearchNsByHref(self->doc, self, nsURI);
6560  
6561 22 ▶ newNode = xmlNewDocNode(self->doc,
Branch: 1 branch
BranchTrueFalseTotal
newNode = xmlNewDocNode(self->doc, 20 2 22
6562 ns,
6563 localname?localname:name,
6564 NULL);
6565 22 ▶ if ( ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == NULL ) { 4 18 22
6566 4 xmlSetNs(newNode,xmlNewNs(newNode, nsURI, prefix));
6567 }
6568  
6569 22 xmlFree(localname);
6570 22 xmlFree(prefix);
6571 22 xmlFree(nsURI);
6572 }
6573 else {
6574 50 newNode = xmlNewDocNode(self->doc,
6575 NULL,
6576 name,
6577 NULL);
6578 }
6579 72 xmlFree(name);
6580 /* add the node to the parent node */
6581 72 newNode->type = XML_ELEMENT_NODE;
6582 72 newNode->parent = self;
6583 72 newNode->doc = self->doc;
6584  
6585 72 ▶ if (self->children == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->children == NULL) { 31 41 72
6586 31 self->children = newNode;
6587 31 self->last = newNode;
6588 } else {
6589 41 prev = self->last;
6590 41 prev->next = newNode;
6591 41 newNode->prev = prev;
6592 41 self->last = newNode;
6593 }
6594 72 ▶ RETVAL = PmmNodeToSv(newNode, PmmOWNERPO(PmmPROXYNODE(self)) );
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = PmmNodeToSv(newNode, PmmOWNERPO(PmmPROXYNODE(self)) ); 72 0 72
RETVAL = PmmNodeToSv(newNode, PmmOWNERPO(PmmPROXYNODE(self)) ); 40 32 72
6595 OUTPUT:
6596 RETVAL
6597  
6598 MODULE = XML::LibXML PACKAGE = XML::LibXML::Text
6599  
6600 SV *
6601 new( CLASS, content )
6602 SV * content
6603 PREINIT:
6604 xmlChar * data;
6605 xmlNodePtr newNode;
6606 18 ProxyNodePtr docfrag = NULL;
6607 CODE:
6608 18 data = Sv2C(content, NULL);
6609 18 newNode = xmlNewText( data );
6610 18 xmlFree(data);
6611 18 ▶ if( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if( newNode != NULL ) { 18 0 18
6612 18 docfrag = PmmNewFragment( NULL );
6613 18 xmlAddChild(PmmNODE(docfrag), newNode);
6614 18 RETVAL = PmmNodeToSv(newNode,docfrag);
6615 }
6616 else {
6617 0 XSRETURN_UNDEF;
6618 }
6619 OUTPUT:
6620 RETVAL
6621  
6622 SV *
6623 substringData( self, offset, length )
6624 xmlNodePtr self
6625 int offset
6626 int length
6627 PREINIT:
6628 4 xmlChar * data = NULL;
6629 4 xmlChar * substr = NULL;
6630 CODE:
6631 4 ▶ if ( offset >= 0 && length >= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( offset >= 0 && length >= 0 ) { 4 0 4
if ( offset >= 0 && length >= 0 ) { 4 0 4
6632 4 data = domGetNodeValue( self );
6633 4 ▶ if ( data != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( data != NULL ) { 4 0 4
6634 4 substr = xmlUTF8Strsub( data, offset, length );
6635 4 RETVAL = C2Sv( (const xmlChar*)substr, NULL );
6636 4 xmlFree( substr );
6637 }
6638 else {
6639 0 XSRETURN_UNDEF;
6640 }
6641 }
6642 else {
6643 0 XSRETURN_UNDEF;
6644 }
6645 OUTPUT:
6646 RETVAL
6647  
6648 void
6649 setData( self, value )
6650 xmlNodePtr self
6651 SV * value
6652 ALIAS:
6653 XML::LibXML::Attr::setValue = 1
6654 XML::LibXML::PI::_setData = 2
6655 PREINIT:
6656 45 xmlChar * encstr = NULL;
6657 CODE:
6658 PERL_UNUSED_VAR(ix);
6659 45 encstr = nodeSv2C(value,self);
6660 45 domSetNodeValue( self, encstr );
6661 45 xmlFree(encstr);
6662  
6663 void
6664 appendData( self, value )
6665 xmlNodePtr self
6666 SV * value
6667 PREINIT:
6668 2 xmlChar * encstring = NULL;
6669 2 int strlen = 0;
6670 CODE:
6671 2 encstring = Sv2C( value,
6672 2 ▶ self->doc!=NULL ? self->doc->encoding : NULL );
Branch: 1 branch
BranchTrueFalseTotal
self->doc!=NULL ? self->doc->encoding : NULL ); 2 0 2
6673  
6674 2 ▶ if ( encstring != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( encstring != NULL ) { 2 0 2
6675 2 strlen = xmlStrlen( encstring );
6676 2 xmlTextConcat( self, encstring, strlen );
6677 2 xmlFree( encstring );
6678 }
6679  
6680 void
6681 insertData( self, offset, value )
6682 xmlNodePtr self
6683 int offset
6684 SV * value
6685 PREINIT:
6686 5 xmlChar * after= NULL;
6687 5 xmlChar * data = NULL;
6688 5 xmlChar * new = NULL;
6689 5 xmlChar * encstring = NULL;
6690 5 int dl = 0;
6691 CODE:
6692 5 ▶ if ( offset >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( offset >= 0 ) { 5 0 5
6693 5 encstring = Sv2C( value,
6694 5 ▶ self->doc!=NULL ? self->doc->encoding : NULL );
Branch: 1 branch
BranchTrueFalseTotal
self->doc!=NULL ? self->doc->encoding : NULL ); 5 0 5
6695 5 ▶ if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) { 5 0 5
if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) { 4 1 5
6696 4 data = domGetNodeValue(self);
6697 4 ▶ if ( data != NULL && xmlStrlen( data ) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( data != NULL && xmlStrlen( data ) > 0 ) { 4 0 4
if ( data != NULL && xmlStrlen( data ) > 0 ) { 4 0 4
6698 4 ▶ if ( xmlUTF8Strlen( data ) < offset ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlUTF8Strlen( data ) < offset ) { 0 4 4
6699 0 data = xmlStrcat( data, encstring );
6700 0 domSetNodeValue( self, data );
6701 }
6702 else {
6703 4 dl = xmlUTF8Strlen( data ) - offset;
6704  
6705 4 ▶ if ( offset > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( offset > 0 ) 4 0 4
6706 4 new = xmlUTF8Strsub(data, 0, offset );
6707  
6708 4 after = xmlUTF8Strsub(data, offset, dl );
6709  
6710 4 ▶ if ( new != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( new != NULL ) { 4 0 4
6711 4 new = xmlStrcat(new, encstring );
6712 }
6713 else {
6714 0 new = xmlStrdup( encstring );
6715 }
6716  
6717 4 ▶ if ( after != NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( after != NULL ) 4 0 4
6718 4 new = xmlStrcat(new, after );
6719  
6720 4 domSetNodeValue( self, new );
6721  
6722 4 xmlFree( new );
6723 4 xmlFree( after );
6724 }
6725 4 xmlFree( data );
6726 }
6727 else {
6728 0 domSetNodeValue( self, encstring );
6729 }
6730 4 xmlFree(encstring);
6731 }
6732 }
6733  
6734 void
6735 deleteData( self, offset, length )
6736 xmlNodePtr self
6737 int offset
6738 int length
6739 PREINIT:
6740 9 xmlChar * data = NULL;
6741 9 xmlChar * after = NULL;
6742 9 xmlChar * new = NULL;
6743 9 int len = 0;
6744 9 int dl1 = 0;
6745 9 int dl2 = 0;
6746 CODE:
6747 9 ▶ if ( length > 0 && offset >= 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( length > 0 && offset >= 0 ) { 7 2 9
if ( length > 0 && offset >= 0 ) { 7 0 7
6748 7 data = domGetNodeValue(self);
6749 7 len = xmlUTF8Strlen( data );
6750 7 ▶ if ( data != NULL
Branch: 1 branch
BranchTrueFalseTotal
if ( data != NULL 7 0 7
6751 7 ▶ && len > 0
Branch: 1 branch
BranchTrueFalseTotal
&& len > 0 7 0 7
6752 7 ▶ && len > offset ) {
Branch: 1 branch
BranchTrueFalseTotal
&& len > offset ) { 5 2 7
6753 5 dl1 = offset + length;
6754 5 ▶ if ( offset > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( offset > 0 ) 4 1 5
6755 4 new = xmlUTF8Strsub( data, 0, offset );
6756  
6757 5 ▶ if ( len > dl1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( len > dl1 ) { 3 2 5
6758 3 dl2 = len - dl1;
6759 3 after = xmlUTF8Strsub( data, dl1, dl2 );
6760 3 ▶ if ( new != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( new != NULL ) { 2 1 3
6761 2 new = xmlStrcat( new, after );
6762 2 xmlFree(after);
6763 }
6764 else {
6765 1 new = after;
6766 }
6767 }
6768  
6769 5 domSetNodeValue( self, new );
6770 5 xmlFree(new);
6771 }
6772 }
6773  
6774 void
6775 replaceData( self, offset,length, value )
6776 xmlNodePtr self
6777 int offset
6778 int length
6779 SV * value
6780 PREINIT:
6781 6 xmlChar * after= NULL;
6782 6 xmlChar * data = NULL;
6783 6 xmlChar * new = NULL;
6784 6 xmlChar * encstring = NULL;
6785 6 int len = 0;
6786 6 int dl1 = 0;
6787 6 int dl2 = 0;
6788 CODE:
6789 6 ▶ if ( offset >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( offset >= 0 ) { 6 0 6
6790 6 encstring = Sv2C( value,
6791 6 ▶ self->doc!=NULL ? self->doc->encoding : NULL );
Branch: 1 branch
BranchTrueFalseTotal
self->doc!=NULL ? self->doc->encoding : NULL ); 6 0 6
6792  
6793 6 ▶ if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) { 6 0 6
if ( encstring != NULL && xmlStrlen( encstring ) > 0 ) { 6 0 6
6794 6 data = domGetNodeValue(self);
6795 6 len = xmlUTF8Strlen( data );
6796  
6797 6 ▶ if ( data != NULL
Branch: 1 branch
BranchTrueFalseTotal
if ( data != NULL 6 0 6
6798 6 ▶ && len > 0
Branch: 1 branch
BranchTrueFalseTotal
&& len > 0 6 0 6
6799 6 ▶ && len > offset ) {
Branch: 1 branch
BranchTrueFalseTotal
&& len > offset ) { 6 0 6
6800  
6801 6 dl1 = offset + length;
6802 6 ▶ if ( dl1 < len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dl1 < len ) { 4 2 6
6803 4 dl2 = xmlUTF8Strlen( data ) - dl1;
6804 4 ▶ if ( offset > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( offset > 0 ) { 4 0 4
6805 4 new = xmlUTF8Strsub(data, 0, offset );
6806 4 new = xmlStrcat(new, encstring );
6807 }
6808 else {
6809 0 new = xmlStrdup( encstring );
6810 }
6811  
6812 4 after = xmlUTF8Strsub(data, dl1, dl2 );
6813 4 new = xmlStrcat(new, after );
6814  
6815 4 domSetNodeValue( self, new );
6816  
6817 4 xmlFree( new );
6818 4 xmlFree( after );
6819 }
6820 else {
6821 /* replace until end! */
6822 2 ▶ if ( offset > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( offset > 0 ) { 2 0 2
6823 2 new = xmlUTF8Strsub(data, 0, offset );
6824 2 new = xmlStrcat(new, encstring );
6825 }
6826 else {
6827 0 new = xmlStrdup( encstring );
6828 }
6829 2 domSetNodeValue( self, new );
6830 2 xmlFree( new );
6831 }
6832 6 xmlFree( data );
6833 }
6834  
6835 6 xmlFree(encstring);
6836 }
6837 }
6838  
6839 MODULE = XML::LibXML PACKAGE = XML::LibXML::Comment
6840  
6841 SV *
6842 new( CLASS, content )
6843 SV * content
6844 PREINIT:
6845 xmlChar * encstring;
6846 xmlNodePtr newNode;
6847 7 ProxyNodePtr docfrag = NULL;
6848 CODE:
6849 7 encstring = Sv2C(content, NULL);
6850 7 newNode = xmlNewComment( encstring );
6851 7 xmlFree(encstring);
6852 7 ▶ if( newNode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if( newNode != NULL ) { 7 0 7
6853 7 docfrag = PmmNewFragment( NULL );
6854 7 xmlAddChild(PmmNODE(docfrag), newNode);
6855 7 RETVAL = PmmNodeToSv(newNode,docfrag);
6856 }
6857 else {
6858 0 XSRETURN_UNDEF;
6859 }
6860 OUTPUT:
6861 RETVAL
6862  
6863 MODULE = XML::LibXML PACKAGE = XML::LibXML::CDATASection
6864  
6865 SV *
6866 new( CLASS , content )
6867 SV * content
6868 PREINIT:
6869 xmlChar * encstring;
6870 xmlNodePtr newNode;
6871 7 ProxyNodePtr docfrag = NULL;
6872 CODE:
6873 7 encstring = Sv2C(content, NULL);
6874 7 newNode = xmlNewCDataBlock( NULL , encstring, xmlStrlen( encstring ) );
6875 7 xmlFree(encstring);
6876 7 ▶ if ( newNode != NULL ){
Branch: 1 branch
BranchTrueFalseTotal
if ( newNode != NULL ){ 7 0 7
6877 7 docfrag = PmmNewFragment( NULL );
6878 7 xmlAddChild(PmmNODE(docfrag), newNode);
6879 7 RETVAL = PmmNodeToSv(newNode,docfrag);
6880 }
6881 else {
6882 0 XSRETURN_UNDEF;
6883 }
6884 OUTPUT:
6885 RETVAL
6886  
6887 MODULE = XML::LibXML PACKAGE = XML::LibXML::DocumentFragment
6888  
6889 SV*
6890 new( CLASS )
6891 PREINIT:
6892 29 xmlNodePtr real_doc=NULL;
6893 CODE:
6894 29 real_doc = xmlNewDocFragment( NULL );
6895 29 RETVAL = PmmNodeToSv( real_doc, NULL );
6896 OUTPUT:
6897 RETVAL
6898  
6899 MODULE = XML::LibXML PACKAGE = XML::LibXML::Attr
6900  
6901 SV*
6902 new( CLASS, pname, pvalue )
6903 SV * pname
6904 SV * pvalue
6905 PREINIT:
6906 0 xmlNodePtr attr = NULL;
6907 xmlChar * name;
6908 xmlChar * value;
6909 CODE:
6910 0 name = Sv2C(pname,NULL);
6911 0 value = Sv2C(pvalue,NULL);
6912 0 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 0 0
6913 0 XSRETURN_UNDEF;
6914 }
6915 0 attr = (xmlNodePtr)xmlNewProp( NULL, name, value );
6916 0 attr->doc = NULL;
6917 0 RETVAL = PmmNodeToSv(attr,NULL);
6918 OUTPUT:
6919 RETVAL
6920  
6921  
6922 SV*
6923 parentElement( self )
6924 ALIAS:
6925 XML::LibXML::Attr::getParentNode = 1
6926 XML::LibXML::Attr::getNextSibling = 2
6927 XML::LibXML::Attr::getPreviousSibling = 3
6928 XML::LibXML::Attr::nextSibling = 4
6929 XML::LibXML::Attr::previousSibling = 5
6930 CODE:
6931 /* override the original parentElement(), since this an attribute is
6932 * not part of the main tree
6933 */
6934  
6935 PERL_UNUSED_VAR(ix);
6936 0 XSRETURN_UNDEF;
6937 OUTPUT:
6938 RETVAL
6939  
6940 SV*
6941 serializeContent( self, useDomEncoding = &PL_sv_undef )
6942 SV * self
6943 SV * useDomEncoding
6944 PREINIT:
6945 xmlBufferPtr buffer;
6946 4 const xmlChar *ret = NULL;
6947 4 xmlAttrPtr node = (xmlAttrPtr)PmmSvNode(self);
6948 CODE:
6949 4 buffer = xmlBufferCreate();
6950 4 domAttrSerializeContent(buffer, node);
6951 4 ▶ if ( xmlBufferLength(buffer) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlBufferLength(buffer) > 0 ) { 4 0 4
6952 4 ret = xmlBufferContent( buffer );
6953 }
6954 4 ▶ if ( ret != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != NULL ) { 4 0 4
6955 4 ▶ if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 0 4 4
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 0 0 0
6956 0 RETVAL = nodeC2Sv((xmlChar*)ret, PmmNODE(PmmPROXYNODE(node))) ;
6957 }
6958 else {
6959 4 RETVAL = C2Sv((xmlChar*)ret, NULL) ;
6960 }
6961 4 xmlBufferFree( buffer );
6962 }
6963 else {
6964 0 xmlBufferFree( buffer );
6965 xs_warn("Failed to convert attribute to string");
6966 0 XSRETURN_UNDEF;
6967 }
6968 OUTPUT:
6969 RETVAL
6970  
6971 SV*
6972 toString(self , format=0, useDomEncoding = &PL_sv_undef )
6973 SV * self
6974 SV * useDomEncoding
6975 int format
6976 ALIAS:
6977 XML::LibXML::Attr::serialize = 1
6978 PREINIT:
6979 10 xmlAttrPtr node = (xmlAttrPtr)PmmSvNode(self);
6980 xmlBufferPtr buffer;
6981 10 ▶ const xmlChar *ret = NULL;
Branch: 1 branch
BranchTrueFalseTotal
const xmlChar *ret = NULL; 10 0 10
6982 CODE:
6983 /* we add an extra method for serializing attributes since
6984 XML::LibXML::Node::toString causes segmentation fault inside
6985 libxml2
6986 */
6987 PERL_UNUSED_VAR(ix);
6988 10 buffer = xmlBufferCreate();
6989 10 xmlBufferAdd(buffer, BAD_CAST " ", 1);
6990 10 ▶ if ((node->ns != NULL) && (node->ns->prefix != NULL)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((node->ns != NULL) && (node->ns->prefix != NULL)) { 2 8 10
if ((node->ns != NULL) && (node->ns->prefix != NULL)) { 2 0 2
6991 2 xmlBufferAdd(buffer, node->ns->prefix, xmlStrlen(node->ns->prefix));
6992 2 xmlBufferAdd(buffer, BAD_CAST ":", 1);
6993 }
6994 10 xmlBufferAdd(buffer, node->name, xmlStrlen(node->name));
6995 10 xmlBufferAdd(buffer, BAD_CAST "=\"", 2);
6996 10 domAttrSerializeContent(buffer, node);
6997 10 xmlBufferAdd(buffer, BAD_CAST "\"", 1);
6998  
6999 10 ▶ if ( xmlBufferLength(buffer) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlBufferLength(buffer) > 0 ) { 10 0 10
7000 10 ret = xmlBufferContent( buffer );
7001 }
7002 10 ▶ if ( ret != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ret != NULL ) { 10 0 10
7003 10 ▶ if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 0 10 10
if ( useDomEncoding != &PL_sv_undef && SvTRUE(useDomEncoding) ) { 0 0 0
7004 0 RETVAL = nodeC2Sv((xmlChar*)ret, PmmNODE(PmmPROXYNODE(node))) ;
7005 }
7006 else {
7007 10 RETVAL = C2Sv((xmlChar*)ret, NULL) ;
7008 }
7009 10 xmlBufferFree( buffer );
7010 }
7011 else {
7012 0 xmlBufferFree( buffer );
7013 xs_warn("Failed to convert attribute to string");
7014 0 XSRETURN_UNDEF;
7015 }
7016 OUTPUT:
7017 RETVAL
7018  
7019  
7020 int
7021 _setNamespace(self, namespaceURI, namespacePrefix = &PL_sv_undef )
7022 SV * self
7023 SV * namespaceURI
7024 SV * namespacePrefix
7025 PREINIT:
7026 2 xmlAttrPtr node = (xmlAttrPtr)PmmSvNode(self);
7027 2 xmlChar * nsURI = nodeSv2C(namespaceURI,(xmlNodePtr)node);
7028 2 xmlChar * nsPrefix = NULL;
7029 2 ▶ xmlNsPtr ns = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNsPtr ns = NULL; 2 0 2
7030 INIT:
7031 2 ▶ if ( node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node == NULL ) { 0 2 2
7032 0 croak( "lost node" );
7033 }
7034 CODE:
7035 2 ▶ if ( !nsURI || xmlStrlen(nsURI)==0 ){
Branch: 2 branches
BranchTrueFalseTotal
if ( !nsURI || xmlStrlen(nsURI)==0 ){ 2 0 2
if ( !nsURI || xmlStrlen(nsURI)==0 ){ 1 1 2
7036 1 xmlSetNs((xmlNodePtr)node, NULL);
7037 1 RETVAL = 1;
7038 }
7039 2 ▶ if ( !node->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !node->parent ) { 0 2 2
7040 0 XSRETURN_UNDEF;
7041 }
7042 2 nsPrefix = nodeSv2C(namespacePrefix, (xmlNodePtr)node);
7043 3 if ( (ns = xmlSearchNs(node->doc, node->parent, nsPrefix)) &&
7044 1 xmlStrEqual( ns->href, nsURI) ) {
7045 /* same uri and prefix */
7046 1 RETVAL = 1;
7047 }
7048 1 ▶ else if ( (ns = xmlSearchNsByHref(node->doc, node->parent, nsURI)) ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( (ns = xmlSearchNsByHref(node->doc, node->parent, nsURI)) ) { 0 1 1
7049 /* set uri, but with a different prefix */
7050 0 RETVAL = 1;
7051 }
7052 1 ▶ else if (! RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
else if (! RETVAL) 0 1 1
7053 0 RETVAL = 0;
7054  
7055 2 ▶ if ( ns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns ) { 1 1 2
7056 1 ▶ if ( ns->prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns->prefix ) { 1 0 1
7057 1 xmlSetNs((xmlNodePtr)node, ns);
7058 } else {
7059 0 RETVAL = 0;
7060 }
7061 }
7062 2 xmlFree(nsPrefix);
7063 2 xmlFree(nsURI);
7064 OUTPUT:
7065 RETVAL
7066  
7067 int
7068 isId( self )
7069 SV * self
7070 PREINIT:
7071 10 xmlAttrPtr attr = (xmlAttrPtr)PmmSvNode(self);
7072 xmlNodePtr elem;
7073 CODE:
7074 10 ▶ if ( attr == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( attr == NULL ) { 0 10 10
7075 0 XSRETURN_UNDEF;
7076 }
7077 10 elem = attr->parent;
7078 10 ▶ if ( elem == NULL || elem->doc == NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elem == NULL || elem->doc == NULL ) { 10 0 10
if ( elem == NULL || elem->doc == NULL ) { 0 10 10
7079 0 XSRETURN_UNDEF;
7080 }
7081 10 RETVAL = xmlIsID( elem->doc, elem, attr );
7082 OUTPUT:
7083 RETVAL
7084  
7085 MODULE = XML::LibXML PACKAGE = XML::LibXML::Namespace
7086  
7087 SV*
7088 new(CLASS, namespaceURI, namespacePrefix=&PL_sv_undef)
7089 const char * CLASS
7090 SV * namespaceURI
7091 SV * namespacePrefix
7092 PREINIT:
7093 14 ▶ xmlNsPtr ns = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNsPtr ns = NULL; 5 9 14
7094 xmlChar* nsURI;
7095 xmlChar* nsPrefix;
7096 CODE:
7097 14 RETVAL = &PL_sv_undef;
7098  
7099 14 nsURI = Sv2C(namespaceURI,NULL);
7100 14 ▶ if ( !nsURI ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !nsURI ) { 0 14 14
7101 0 XSRETURN_UNDEF;
7102 }
7103 14 nsPrefix = Sv2C(namespacePrefix, NULL);
7104 14 ns = xmlNewNs(NULL, nsURI, nsPrefix);
7105 14 ▶ if ( ns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns ) { 14 0 14
7106 14 RETVAL = NEWSV(0,0);
7107 14 RETVAL = sv_setref_pv( RETVAL,
7108 CLASS,
7109 (void*)ns);
7110 }
7111 14 xmlFree(nsURI);
7112 14 ▶ if ( nsPrefix )
Branch: 1 branch
BranchTrueFalseTotal
if ( nsPrefix ) 9 5 14
7113 9 xmlFree(nsPrefix);
7114 OUTPUT:
7115 RETVAL
7116  
7117 void
7118 DESTROY(self)
7119 SV * self
7120 PREINIT:
7121 37 xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
7122 CODE:
7123 xs_warn( "DESTROY NS" );
7124 37 ▶ if (ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns) { 37 0 37
7125 37 xmlFreeNs(ns);
7126 }
7127  
7128 int
7129 nodeType(self)
7130 SV * self
7131 ALIAS:
7132 getType = 1
7133 PREINIT:
7134 3 ▶ xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
Branch: 1 branch
BranchTrueFalseTotal
xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self))); 3 0 3
7135 CODE:
7136 PERL_UNUSED_VAR(ix);
7137 3 ▶ RETVAL = ns->type;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ns->type; 0 3 3
7138 OUTPUT:
7139 RETVAL
7140  
7141 SV*
7142 declaredURI(self)
7143 SV * self
7144 ALIAS:
7145 value = 1
7146 nodeValue = 2
7147 getData = 3
7148 getValue = 4
7149 value2 = 5
7150 href = 6
7151 PREINIT:
7152 12 xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
7153 xmlChar * href;
7154 CODE:
7155 PERL_UNUSED_VAR(ix);
7156 12 href = xmlStrdup(ns->href);
7157 12 RETVAL = C2Sv(href, NULL);
7158 12 xmlFree(href);
7159 OUTPUT:
7160 RETVAL
7161  
7162 SV*
7163 declaredPrefix(self)
7164 SV * self
7165 ALIAS:
7166 localname = 1
7167 getLocalName = 2
7168 PREINIT:
7169 20 xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
7170 xmlChar * prefix;
7171 CODE:
7172 PERL_UNUSED_VAR(ix);
7173 20 prefix = xmlStrdup(ns->prefix);
7174 20 RETVAL = C2Sv(prefix, NULL);
7175 20 xmlFree(prefix);
7176 OUTPUT:
7177 RETVAL
7178  
7179 SV*
7180 unique_key( self )
7181 SV * self
7182 PREINIT:
7183 10 xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
7184 xmlChar* key;
7185 CODE:
7186 /* Concatenate prefix and URI with vertical bar dividing*/
7187 10 key = xmlStrdup(ns->prefix);
7188 10 key = xmlStrcat(key, (const xmlChar*)"|");
7189 10 key = xmlStrcat(key, ns->href);
7190 10 RETVAL = C2Sv(key, NULL);
7191 OUTPUT:
7192 RETVAL
7193  
7194 int
7195 _isEqual(self, ref_node)
7196 SV * self
7197 SV * ref_node
7198 PREINIT:
7199 0 xmlNsPtr ns = INT2PTR(xmlNsPtr,SvIV(SvRV(self)));
7200 0 ▶ xmlNsPtr ons = INT2PTR(xmlNsPtr,SvIV(SvRV(ref_node)));
Branch: 1 branch
BranchTrueFalseTotal
xmlNsPtr ons = INT2PTR(xmlNsPtr,SvIV(SvRV(ref_node))); 0 0 0
7201 CODE:
7202 0 RETVAL = 0;
7203 0 ▶ if ( ns == ons ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns == ons ) { 0 0 0
7204 0 RETVAL = 1;
7205 }
7206 0 ▶ else if ( xmlStrEqual(ns->href, ons->href)
Branch: 1 branch
BranchTrueFalseTotal
else if ( xmlStrEqual(ns->href, ons->href) 0 0 0
7207 0 ▶ && xmlStrEqual(ns->prefix, ons->prefix) ) {
Branch: 1 branch
BranchTrueFalseTotal
&& xmlStrEqual(ns->prefix, ons->prefix) ) { 0 0 0
7208 0 RETVAL = 1;
7209 }
7210 OUTPUT:
7211 RETVAL
7212  
7213  
7214 MODULE = XML::LibXML PACKAGE = XML::LibXML::Dtd
7215  
7216 SV *
7217 new(CLASS, external, system)
7218 char * external
7219 char * system
7220 ALIAS:
7221 parse_uri = 1
7222 PREINIT:
7223 4 xmlDtdPtr dtd = NULL;
7224 4 PREINIT_SAVED_ERROR
7225 CODE:
7226 PERL_UNUSED_VAR(ix);
7227 4 INIT_ERROR_HANDLER;
7228 4 dtd = xmlParseDTD((const xmlChar*)external, (const xmlChar*)system);
7229 4 ▶ if ( dtd == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dtd == NULL ) { 2 2 4
7230 2 CLEANUP_ERROR_HANDLER;
7231 2 REPORT_ERROR(0);
7232 1 XSRETURN_UNDEF;
7233 } else {
7234 2 xmlSetTreeDoc((xmlNodePtr)dtd, NULL);
7235 2 RETVAL = PmmNodeToSv( (xmlNodePtr) dtd, NULL );
7236 2 CLEANUP_ERROR_HANDLER;
7237 2 REPORT_ERROR(0);
7238 }
7239 OUTPUT:
7240 RETVAL
7241  
7242 SV*
7243 systemId( self )
7244 xmlDtdPtr self
7245 ALIAS:
7246 getSystemId = 1
7247 CODE:
7248 PERL_UNUSED_VAR(ix);
7249 3 ▶ if ( self->SystemID == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->SystemID == NULL ) { 1 2 3
7250 1 XSRETURN_UNDEF;
7251 } else {
7252 2 RETVAL = C2Sv(self->SystemID,NULL);
7253 }
7254 OUTPUT:
7255 RETVAL
7256  
7257 SV*
7258 publicId( self )
7259 xmlDtdPtr self
7260 ALIAS:
7261 getPublicId = 1
7262 CODE:
7263 PERL_UNUSED_VAR(ix);
7264 3 ▶ if ( self->ExternalID == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( self->ExternalID == NULL ) { 1 2 3
7265 1 XSRETURN_UNDEF;
7266 } else {
7267 2 RETVAL = C2Sv(self->ExternalID,NULL);
7268 }
7269 OUTPUT:
7270 RETVAL
7271  
7272 SV *
7273 parse_string(CLASS, str, ...)
7274 char * str
7275 PREINIT:
7276 xmlDtdPtr res;
7277 SV * encoding_sv;
7278 xmlParserInputBufferPtr buffer;
7279 4 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
7280 xmlChar * new_string;
7281 4 PREINIT_SAVED_ERROR
7282 CODE:
7283 4 INIT_ERROR_HANDLER;
7284 4 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 0 4 4
7285 0 encoding_sv = ST(2);
7286 0 ▶ if (items > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) { 0 0 0
7287 0 CLEANUP_ERROR_HANDLER;
7288 0 croak("parse_string: too many parameters");
7289 }
7290 /* warn("getting encoding...\n"); */
7291 0 enc = xmlParseCharEncoding(SvPV_nolen(encoding_sv));
7292 0 ▶ if (enc == XML_CHAR_ENCODING_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if (enc == XML_CHAR_ENCODING_ERROR) { 0 0 0
7293 0 CLEANUP_ERROR_HANDLER;
7294 0 REPORT_ERROR(1);
7295 0 croak("Parse of encoding %s failed", SvPV_nolen(encoding_sv));
7296 }
7297 }
7298 4 buffer = xmlAllocParserInputBuffer(enc);
7299 /* buffer = xmlParserInputBufferCreateMem(str, xmlStrlen(str), enc); */
7300 4 ▶ if ( !buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !buffer) { 0 4 4
7301 0 CLEANUP_ERROR_HANDLER;
7302 0 REPORT_ERROR(1);
7303 0 croak("cannot create buffer!\n" );
7304 }
7305 4 new_string = xmlStrdup((const xmlChar*)str);
7306 4 xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*)new_string);
7307  
7308 4 res = xmlIOParseDTD(NULL, buffer, enc);
7309  
7310 /* NOTE: xmlIOParseDTD is documented to free its InputBuffer */
7311 4 xmlFree(new_string);
7312 4 ▶ if ( res && LibXML_will_die_ctx(saved_error, 0) )
Branch: 2 branches
BranchTrueFalseTotal
if ( res && LibXML_will_die_ctx(saved_error, 0) ) 3 1 4
if ( res && LibXML_will_die_ctx(saved_error, 0) ) 0 3 3
7313 0 xmlFreeDtd( res );
7314 4 CLEANUP_ERROR_HANDLER;
7315 4 REPORT_ERROR(0);
7316 3 ▶ if (res == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (res == NULL) { 0 3 3
7317 0 croak("no DTD parsed!");
7318 }
7319 3 RETVAL = PmmNodeToSv((xmlNodePtr)res, NULL);
7320 OUTPUT:
7321 RETVAL
7322  
7323  
7324 #ifdef HAVE_SCHEMAS
7325  
7326 MODULE = XML::LibXML PACKAGE = XML::LibXML::RelaxNG
7327  
7328 void
7329 DESTROY( self )
7330 xmlRelaxNGPtr self
7331 CODE:
7332 6 xmlRelaxNGFree( self );
7333  
7334  
7335 xmlRelaxNGPtr
7336 parse_location( self, url, parser_options = 0, recover = FALSE )
7337 char * url
7338 int parser_options
7339 bool recover
7340 PREINIT:
7341 6 const char * CLASS = "XML::LibXML::RelaxNG";
7342 6 xmlRelaxNGParserCtxtPtr rngctxt = NULL;
7343 6 xmlExternalEntityLoader old_ext_ent_loader = NULL;
7344 6 PREINIT_SAVED_ERROR
7345 CODE:
7346 6 INIT_ERROR_HANDLER;
7347  
7348 6 rngctxt = xmlRelaxNGNewParserCtxt( url );
7349 6 ▶ if ( rngctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rngctxt == NULL ) { 0 6 6
7350 0 croak( "failed to initialize RelaxNG parser" );
7351 }
7352 #ifndef WITH_SERRORS
7353 /* Register Error callbacks */
7354 xmlRelaxNGSetParserErrors( rngctxt,
7355 (xmlRelaxNGValidityErrorFunc)LibXML_error_handler_ctx,
7356 (xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
7357 saved_error );
7358 #endif
7359  
7360 6 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 6 0 6
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 1 5 6
7361 1 old_ext_ent_loader = xmlGetExternalEntityLoader();
7362 1 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
7363 }
7364  
7365 6 RETVAL = xmlRelaxNGParse( rngctxt );
7366  
7367 6 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 6 0 6
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 1 5 6
7368 1 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
7369  
7370 6 xmlRelaxNGFreeParserCtxt( rngctxt );
7371 6 CLEANUP_ERROR_HANDLER;
7372 6 ▶ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR((RETVAL == NULL) ? 0 : recover); 4 2 6
7373 OUTPUT:
7374 RETVAL
7375  
7376  
7377 xmlRelaxNGPtr
7378 parse_buffer( self, perlstring, parser_options = 0, recover = FALSE )
7379 SV * perlstring
7380 int parser_options
7381 bool recover
7382 PREINIT:
7383 3 const char * CLASS = "XML::LibXML::RelaxNG";
7384 3 xmlRelaxNGParserCtxtPtr rngctxt = NULL;
7385 3 xmlExternalEntityLoader old_ext_ent_loader = NULL;
7386 3 char * string = NULL;
7387 3 STRLEN len = 0;
7388 3 PREINIT_SAVED_ERROR
7389 INIT:
7390 3 string = SvPV( perlstring, len );
7391 3 ▶ if ( string == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( string == NULL ) { 0 3 3
7392 0 croak( "cannot parse empty string" );
7393 }
7394 CODE:
7395 3 INIT_ERROR_HANDLER;
7396  
7397 3 rngctxt = xmlRelaxNGNewMemParserCtxt( string,len );
7398 3 ▶ if ( rngctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rngctxt == NULL ) { 0 3 3
7399 0 croak( "failed to initialize RelaxNG parser" );
7400 }
7401 #ifndef WITH_SERRORS
7402 /* Register Error callbacks */
7403 xmlRelaxNGSetParserErrors( rngctxt,
7404 (xmlRelaxNGValidityErrorFunc)LibXML_error_handler_ctx,
7405 (xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
7406 saved_error );
7407 #endif
7408  
7409 3 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 3 0 3
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 1 2 3
7410 1 old_ext_ent_loader = xmlGetExternalEntityLoader();
7411 1 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
7412 }
7413  
7414 3 RETVAL = xmlRelaxNGParse( rngctxt );
7415  
7416 3 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 3 0 3
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 1 2 3
7417 1 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
7418  
7419 3 xmlRelaxNGFreeParserCtxt( rngctxt );
7420 3 CLEANUP_ERROR_HANDLER;
7421 3 ▶ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR((RETVAL == NULL) ? 0 : recover); 1 2 3
7422 OUTPUT:
7423 RETVAL
7424  
7425  
7426 xmlRelaxNGPtr
7427 parse_document( self, doc, parser_options = 0, recover = FALSE )
7428 xmlDocPtr doc
7429 int parser_options
7430 bool recover
7431 PREINIT:
7432 2 const char * CLASS = "XML::LibXML::RelaxNG";
7433 2 xmlRelaxNGParserCtxtPtr rngctxt = NULL;
7434 2 xmlExternalEntityLoader old_ext_ent_loader = NULL;
7435 2 PREINIT_SAVED_ERROR
7436 CODE:
7437 2 INIT_ERROR_HANDLER;
7438  
7439 2 rngctxt = xmlRelaxNGNewDocParserCtxt( doc );
7440 2 ▶ if ( rngctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rngctxt == NULL ) { 0 2 2
7441 0 croak( "failed to initialize RelaxNG parser" );
7442 }
7443 #ifndef WITH_SERRORS
7444 /* Register Error callbacks */
7445 xmlRelaxNGSetParserErrors( rngctxt,
7446 (xmlRelaxNGValidityErrorFunc) LibXML_error_handler_ctx,
7447 (xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
7448 saved_error );
7449 #endif
7450  
7451 2 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 2 0 2
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 0 2 2
7452 0 old_ext_ent_loader = xmlGetExternalEntityLoader();
7453 0 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
7454 }
7455  
7456 2 RETVAL = xmlRelaxNGParse( rngctxt );
7457  
7458 2 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 2 0 2
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 0 2 2
7459 0 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
7460  
7461 2 xmlRelaxNGFreeParserCtxt( rngctxt );
7462 2 CLEANUP_ERROR_HANDLER;
7463 2 ▶ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR((RETVAL == NULL) ? 0 : recover); 1 1 2
7464 OUTPUT:
7465 RETVAL
7466  
7467 int
7468 validate( self, doc )
7469 xmlRelaxNGPtr self
7470 xmlDocPtr doc
7471 PREINIT:
7472 7 xmlRelaxNGValidCtxtPtr vctxt = NULL;
7473 7 PREINIT_SAVED_ERROR
7474 CODE:
7475 7 INIT_ERROR_HANDLER;
7476  
7477 7 ▶ if (doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (doc) { 7 0 7
7478 7 ▶ PmmClearPSVI(doc);
Branch: 4 branches
BranchTrueFalseTotal
PmmClearPSVI(doc); 7 0 7
PmmClearPSVI(doc); 7 0 7
PmmClearPSVI(doc); 7 0 7
PmmClearPSVI(doc); 4 3 7
7479 7 ▶ PmmInvalidatePSVI(doc);
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI(doc); 7 0 7
PmmInvalidatePSVI(doc); 7 0 7
7480 }
7481 7 vctxt = xmlRelaxNGNewValidCtxt( self );
7482 7 ▶ if ( vctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( vctxt == NULL ) { 0 7 7
7483 0 CLEANUP_ERROR_HANDLER;
7484 0 REPORT_ERROR(0);
7485 0 croak( "cannot initialize the validation context" );
7486 }
7487 #ifndef WITH_SERRORS
7488 /* Register Error callbacks */
7489 xmlRelaxNGSetValidErrors( vctxt,
7490 (xmlRelaxNGValidityErrorFunc)LibXML_error_handler_ctx,
7491 (xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
7492 saved_error );
7493 #endif /* WITH_SERRORS */
7494 /* ** test only **
7495 xmlRelaxNGSetValidErrors( vctxt,
7496 (xmlRelaxNGValidityErrorFunc)fprintf,
7497 (xmlRelaxNGValidityWarningFunc)fprintf,
7498 stderr );
7499 */
7500 7 RETVAL = xmlRelaxNGValidateDoc( vctxt, doc );
7501 7 xmlRelaxNGFreeValidCtxt( vctxt );
7502 7 CLEANUP_ERROR_HANDLER;
7503 7 REPORT_ERROR(0);
7504 3 ▶ if ( RETVAL == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == 1 ) { 0 3 3
7505 0 XSRETURN_UNDEF;
7506 }
7507 3 ▶ if ( RETVAL == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == -1 ) { 0 3 3
7508 0 croak( "API Error" );
7509 XSRETURN_UNDEF;
7510 }
7511 OUTPUT:
7512 RETVAL
7513  
7514  
7515 MODULE = XML::LibXML PACKAGE = XML::LibXML::Schema
7516  
7517 void
7518 DESTROY( self )
7519 xmlSchemaPtr self
7520 CODE:
7521 5 xmlSchemaFree( self );
7522  
7523  
7524 xmlSchemaPtr
7525 parse_location( self, url, parser_options = 0, recover = FALSE )
7526 char * url
7527 int parser_options
7528 bool recover
7529 PREINIT:
7530 5 const char * CLASS = "XML::LibXML::Schema";
7531 5 xmlSchemaParserCtxtPtr rngctxt = NULL;
7532 5 xmlExternalEntityLoader old_ext_ent_loader = NULL;
7533 5 PREINIT_SAVED_ERROR
7534 CODE:
7535 5 INIT_ERROR_HANDLER;
7536  
7537 5 rngctxt = xmlSchemaNewParserCtxt( url );
7538 5 ▶ if ( rngctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rngctxt == NULL ) { 0 5 5
7539 0 CLEANUP_ERROR_HANDLER;
7540 0 REPORT_ERROR(0);
7541 0 croak( "failed to initialize Schema parser" );
7542 }
7543  
7544 /* Register Error callbacks */
7545 5 xmlSchemaSetParserErrors( rngctxt,
7546 (xmlSchemaValidityErrorFunc)LibXML_error_handler_ctx,
7547 (xmlSchemaValidityWarningFunc)LibXML_error_handler_ctx,
7548 saved_error );
7549  
7550 5 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 5 0 5
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 1 4 5
7551 1 old_ext_ent_loader = xmlGetExternalEntityLoader();
7552 1 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
7553 }
7554  
7555 5 RETVAL = xmlSchemaParse( rngctxt );
7556  
7557 5 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 5 0 5
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 1 4 5
7558 1 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
7559  
7560 5 xmlSchemaFreeParserCtxt( rngctxt );
7561 5 CLEANUP_ERROR_HANDLER;
7562 5 ▶ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR((RETVAL == NULL) ? 0 : recover); 4 1 5
7563 OUTPUT:
7564 RETVAL
7565  
7566  
7567 xmlSchemaPtr
7568 parse_buffer( self, perlstring, parser_options = 0, recover = FALSE )
7569 SV * perlstring
7570 int parser_options
7571 bool recover
7572 PREINIT:
7573 4 const char * CLASS = "XML::LibXML::Schema";
7574 4 xmlSchemaParserCtxtPtr rngctxt = NULL;
7575 4 xmlExternalEntityLoader old_ext_ent_loader = NULL;
7576 4 char * string = NULL;
7577 4 STRLEN len = 0;
7578 4 PREINIT_SAVED_ERROR
7579 INIT:
7580 4 string = SvPV( perlstring, len );
7581 4 ▶ if ( string == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( string == NULL ) { 0 4 4
7582 0 croak( "cannot parse empty string" );
7583 }
7584 CODE:
7585 4 INIT_ERROR_HANDLER;
7586  
7587 4 rngctxt = xmlSchemaNewMemParserCtxt( string,len );
7588 4 ▶ if ( rngctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rngctxt == NULL ) { 0 4 4
7589 0 CLEANUP_ERROR_HANDLER;
7590 0 REPORT_ERROR(0);
7591 0 croak( "failed to initialize Schema parser" );
7592 }
7593  
7594 /* Register Error callbacks */
7595 4 xmlSchemaSetParserErrors( rngctxt,
7596 (xmlSchemaValidityErrorFunc)LibXML_error_handler_ctx,
7597 (xmlSchemaValidityWarningFunc)LibXML_error_handler_ctx,
7598 saved_error );
7599  
7600 4 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 4 0 4
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) { 1 3 4
7601 1 old_ext_ent_loader = xmlGetExternalEntityLoader();
7602 1 xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
7603 }
7604  
7605 4 RETVAL = xmlSchemaParse( rngctxt );
7606  
7607 4 ▶ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
Branch: 2 branches
BranchTrueFalseTotal
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 4 0 4
if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) 1 3 4
7608 1 xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
7609  
7610 4 xmlSchemaFreeParserCtxt( rngctxt );
7611 4 CLEANUP_ERROR_HANDLER;
7612 4 ▶ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
Branch: 1 branch
BranchTrueFalseTotal
REPORT_ERROR((RETVAL == NULL) ? 0 : recover); 3 1 4
7613 OUTPUT:
7614 RETVAL
7615  
7616  
7617 int
7618 validate( self, node )
7619 xmlSchemaPtr self
7620 xmlNodePtr node
7621 PREINIT:
7622 3 xmlSchemaValidCtxtPtr vctxt = NULL;
7623 3 PREINIT_SAVED_ERROR
7624 CODE:
7625 3 INIT_ERROR_HANDLER;
7626  
7627 3 ▶ if (node->type == XML_DOCUMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_DOCUMENT_NODE) { 2 1 3
7628 2 ▶ PmmClearPSVI((xmlDocPtr)node);
Branch: 4 branches
BranchTrueFalseTotal
PmmClearPSVI((xmlDocPtr)node); 2 0 2
PmmClearPSVI((xmlDocPtr)node); 2 0 2
PmmClearPSVI((xmlDocPtr)node); 2 0 2
PmmClearPSVI((xmlDocPtr)node); 0 2 2
7629 2 ▶ PmmInvalidatePSVI((xmlDocPtr)node);
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI((xmlDocPtr)node); 2 0 2
PmmInvalidatePSVI((xmlDocPtr)node); 2 0 2
7630 }
7631 3 vctxt = xmlSchemaNewValidCtxt( self );
7632 3 ▶ if ( vctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( vctxt == NULL ) { 0 3 3
7633 0 CLEANUP_ERROR_HANDLER;
7634 0 REPORT_ERROR(0);
7635 0 croak( "cannot initialize the validation context" );
7636 }
7637  
7638 /* Register Error callbacks */
7639 3 xmlSchemaSetValidErrors( vctxt,
7640 (xmlSchemaValidityErrorFunc)LibXML_error_handler_ctx,
7641 (xmlSchemaValidityWarningFunc)LibXML_error_handler_ctx,
7642 saved_error );
7643  
7644 3 ▶ if (node->type == XML_DOCUMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->type == XML_DOCUMENT_NODE) { 2 1 3
7645 2 RETVAL = xmlSchemaValidateDoc(vctxt, (xmlDocPtr)node);
7646 }
7647 else {
7648 1 RETVAL = xmlSchemaValidateOneElement(vctxt, node);
7649 }
7650  
7651 3 xmlSchemaFreeValidCtxt( vctxt );
7652  
7653 3 CLEANUP_ERROR_HANDLER;
7654 3 REPORT_ERROR(0);
7655 2 ▶ if ( RETVAL > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL > 0 ) { 0 2 2
7656 0 XSRETURN_UNDEF;
7657 }
7658 2 ▶ if ( RETVAL == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == -1 ) { 0 2 2
7659 0 croak( "API Error" );
7660 XSRETURN_UNDEF;
7661 }
7662 OUTPUT:
7663 RETVAL
7664  
7665 #endif /* HAVE_SCHEMAS */
7666  
7667 MODULE = XML::LibXML::XPathContext PACKAGE = XML::LibXML::XPathContext
7668  
7669 # PROTOTYPES: DISABLE
7670  
7671 SV*
7672 new( CLASS, ... )
7673 const char * CLASS
7674 PREINIT:
7675 32 SV * pnode = &PL_sv_undef;
7676 INIT:
7677 xmlXPathContextPtr ctxt;
7678 CODE:
7679 32 ▶ if( items > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if( items > 1 ) 26 6 32
7680 26 pnode = ST(1);
7681  
7682 32 ctxt = xmlXPathNewContext( NULL );
7683 32 ctxt->namespaces = NULL;
7684  
7685 32 New(0, ctxt->user, sizeof(XPathContextData), XPathContextData);
7686 32 ▶ if (ctxt->user == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->user == NULL) { 0 32 32
7687 0 croak("XPathContext: failed to allocate proxy object\n");
7688 }
7689  
7690 32 ▶ if (SvOK(pnode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(pnode)) { 26 6 32
7691 26 XPathContextDATA(ctxt)->node = newSVsv(pnode);
7692 } else {
7693 6 XPathContextDATA(ctxt)->node = &PL_sv_undef;
7694 }
7695  
7696 32 XPathContextDATA(ctxt)->pool = NULL;
7697 32 XPathContextDATA(ctxt)->varLookup = NULL;
7698 32 XPathContextDATA(ctxt)->varData = NULL;
7699  
7700 32 xmlXPathRegisterFunc(ctxt,
7701 (const xmlChar *) "document",
7702 perlDocumentFunction);
7703  
7704 32 RETVAL = NEWSV(0,0),
7705 32 RETVAL = sv_setref_pv( RETVAL,
7706 CLASS,
7707 (void*)ctxt );
7708 OUTPUT:
7709 RETVAL
7710  
7711 void
7712 DESTROY( self )
7713 SV * self
7714 INIT:
7715 32 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7716 CODE:
7717 xs_warn( "DESTROY XPATH CONTEXT" );
7718 32 ▶ if (ctxt) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt) { 32 0 32
7719 32 ▶ if (XPathContextDATA(ctxt) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt) != NULL) { 32 0 32
7720 32 ▶ if (XPathContextDATA(ctxt)->node != NULL &&
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->node != NULL && 30 2 32
7721 30 ▶ SvOK(XPathContextDATA(ctxt)->node)) {
Branch: 1 branch
BranchTrueFalseTotal
SvOK(XPathContextDATA(ctxt)->node)) { 27 3 30
7722 27 SvREFCNT_dec(XPathContextDATA(ctxt)->node);
7723 }
7724 32 ▶ if (XPathContextDATA(ctxt)->varLookup != NULL &&
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->varLookup != NULL && 2 30 32
7725 2 ▶ SvOK(XPathContextDATA(ctxt)->varLookup)) {
Branch: 1 branch
BranchTrueFalseTotal
SvOK(XPathContextDATA(ctxt)->varLookup)) { 2 0 2
7726 2 SvREFCNT_dec(XPathContextDATA(ctxt)->varLookup);
7727 }
7728 32 ▶ if (XPathContextDATA(ctxt)->varData != NULL &&
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->varData != NULL && 1 31 32
7729 1 ▶ SvOK(XPathContextDATA(ctxt)->varData)) {
Branch: 1 branch
BranchTrueFalseTotal
SvOK(XPathContextDATA(ctxt)->varData)) { 1 0 1
7730 1 SvREFCNT_dec(XPathContextDATA(ctxt)->varData);
7731 }
7732 32 ▶ if (XPathContextDATA(ctxt)->pool != NULL &&
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->pool != NULL && 0 32 32
7733 0 ▶ SvOK(XPathContextDATA(ctxt)->pool)) {
Branch: 1 branch
BranchTrueFalseTotal
SvOK(XPathContextDATA(ctxt)->pool)) { 0 0 0
7734 0 SvREFCNT_dec((SV *)XPathContextDATA(ctxt)->pool);
7735 }
7736 32 Safefree(XPathContextDATA(ctxt));
7737 }
7738  
7739 32 ▶ if (ctxt->namespaces != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->namespaces != NULL) { 4 28 32
7740 4 xmlFree( ctxt->namespaces );
7741 }
7742 32 ▶ if (ctxt->funcLookupData != NULL && SvROK((SV*)ctxt->funcLookupData)
Branch: 2 branches
BranchTrueFalseTotal
if (ctxt->funcLookupData != NULL && SvROK((SV*)ctxt->funcLookupData) 3 29 32
if (ctxt->funcLookupData != NULL && SvROK((SV*)ctxt->funcLookupData) 3 0 3
7743 3 ▶ && SvTYPE(SvRV((SV *)ctxt->funcLookupData)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV((SV *)ctxt->funcLookupData)) == SVt_PVHV) { 3 0 3
7744 3 SvREFCNT_dec((SV *)ctxt->funcLookupData);
7745 }
7746  
7747 32 xmlXPathFreeContext(ctxt);
7748 }
7749  
7750 SV*
7751 getContextNode( self )
7752 SV * self
7753 INIT:
7754 27 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7755 27 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 27 27
7756 0 croak("XPathContext: missing xpath context\n");
7757 }
7758 CODE:
7759 27 ▶ if(XPathContextDATA(ctxt)->node != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(XPathContextDATA(ctxt)->node != NULL) { 14 13 27
7760 14 RETVAL = newSVsv(XPathContextDATA(ctxt)->node);
7761 } else {
7762 13 RETVAL = &PL_sv_undef;
7763 }
7764 OUTPUT:
7765 RETVAL
7766  
7767 int
7768 getContextPosition( self )
7769 SV * self
7770 INIT:
7771 4 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7772 4 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 4 4
7773 0 croak("XPathContext: missing xpath context\n");
7774 }
7775 CODE:
7776 4 ▶ RETVAL = ctxt->proximityPosition;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ctxt->proximityPosition; 0 4 4
7777 OUTPUT:
7778 RETVAL
7779  
7780 int
7781 getContextSize( self )
7782 SV * self
7783 INIT:
7784 5 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7785 5 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 5 5
7786 0 croak("XPathContext: missing xpath context\n");
7787 }
7788 CODE:
7789 5 ▶ RETVAL = ctxt->contextSize;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ctxt->contextSize; 0 5 5
7790 OUTPUT:
7791 RETVAL
7792  
7793 void
7794 setContextNode( self , pnode )
7795 SV * self
7796 SV * pnode
7797 INIT:
7798 40 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7799 40 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 40 40
7800 0 croak("XPathContext: missing xpath context\n");
7801 }
7802 PPCODE:
7803 40 ▶ if (XPathContextDATA(ctxt)->node != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->node != NULL) { 27 13 40
7804 27 SvREFCNT_dec(XPathContextDATA(ctxt)->node);
7805 }
7806 40 ▶ if (SvOK(pnode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(pnode)) { 25 15 40
7807 25 XPathContextDATA(ctxt)->node = newSVsv(pnode);
7808 } else {
7809 15 XPathContextDATA(ctxt)->node = NULL;
7810 }
7811  
7812 void
7813 setContextPosition( self , position )
7814 SV * self
7815 int position
7816 INIT:
7817 4 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7818 4 ▶ if ( ctxt == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) 0 4 4
7819 0 croak("XPathContext: missing xpath context\n");
7820 4 ▶ if ( position < -1 || position > ctxt->contextSize )
Branch: 2 branches
BranchTrueFalseTotal
if ( position < -1 || position > ctxt->contextSize ) 3 1 4
if ( position < -1 || position > ctxt->contextSize ) 2 1 3
7821 3 croak("XPathContext: invalid position\n");
7822 PPCODE:
7823 1 ctxt->proximityPosition = position;
7824  
7825 void
7826 setContextSize( self , size )
7827 SV * self
7828 int size
7829 INIT:
7830 4 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7831 4 ▶ if ( ctxt == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) 0 4 4
7832 0 croak("XPathContext: missing xpath context\n");
7833 4 ▶ if ( size < -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ( size < -1 ) 1 3 4
7834 1 croak("XPathContext: invalid size\n");
7835 PPCODE:
7836 3 ctxt->contextSize = size;
7837 3 ▶ if ( size == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( size == 0 ) 1 2 3
7838 1 ctxt->proximityPosition = 0;
7839 2 ▶ else if ( size > 0 )
Branch: 1 branch
BranchTrueFalseTotal
else if ( size > 0 ) 1 1 2
7840 1 ctxt->proximityPosition = 1;
7841 else
7842 1 ctxt->proximityPosition = -1;
7843  
7844 void
7845 registerNs( pxpath_context, prefix, ns_uri )
7846 SV * pxpath_context
7847 SV * prefix
7848 SV * ns_uri
7849 PREINIT:
7850 11 xmlXPathContextPtr ctxt = NULL;
7851 INIT:
7852 11 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
7853 11 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 11 11
7854 0 croak("XPathContext: missing xpath context\n");
7855 }
7856 11 LibXML_configure_xpathcontext(ctxt);
7857 PPCODE:
7858 11 ▶ if(SvOK(ns_uri)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvOK(ns_uri)) { 8 3 11
7859 8 ▶ if(xmlXPathRegisterNs(ctxt, (xmlChar *) SvPV_nolen(prefix),
Branch: 1 branch
BranchTrueFalseTotal
if(xmlXPathRegisterNs(ctxt, (xmlChar *) SvPV_nolen(prefix), 0 8 8
7860 8 ▶ (xmlChar *) SvPV_nolen(ns_uri)) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
(xmlChar *) SvPV_nolen(ns_uri)) == -1) { 8 0 8
7861 0 croak("XPathContext: cannot register namespace\n");
7862 }
7863 } else {
7864 3 ▶ if(xmlXPathRegisterNs(ctxt, (xmlChar *) SvPV_nolen(prefix), NULL) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if(xmlXPathRegisterNs(ctxt, (xmlChar *) SvPV_nolen(prefix), NULL) == -1) { 0 3 3
7865 0 croak("XPathContext: cannot unregister namespace\n");
7866 }
7867 }
7868  
7869 SV*
7870 lookupNs( pxpath_context, prefix )
7871 SV * pxpath_context
7872 SV * prefix
7873 PREINIT:
7874 3 xmlXPathContextPtr ctxt = NULL;
7875 INIT:
7876 3 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
7877 3 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 3 3
7878 0 croak("XPathContext: missing xpath context\n");
7879 }
7880 3 LibXML_configure_xpathcontext(ctxt);
7881 CODE:
7882 3 RETVAL = C2Sv(xmlXPathNsLookup(ctxt, (xmlChar *) SvPV_nolen(prefix)), NULL);
7883 OUTPUT:
7884 RETVAL
7885  
7886 SV*
7887 getVarLookupData( self )
7888 SV * self
7889 INIT:
7890 6 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7891 6 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 6 6
7892 0 croak("XPathContext: missing xpath context\n");
7893 }
7894 CODE:
7895 6 ▶ if(XPathContextDATA(ctxt)->varData != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(XPathContextDATA(ctxt)->varData != NULL) { 5 1 6
7896 5 RETVAL = newSVsv(XPathContextDATA(ctxt)->varData);
7897 } else {
7898 1 RETVAL = &PL_sv_undef;
7899 }
7900 OUTPUT:
7901 RETVAL
7902  
7903 SV*
7904 getVarLookupFunc( self )
7905 SV * self
7906 INIT:
7907 2 xmlXPathContextPtr ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(self)));
7908 2 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 2 2
7909 0 croak("XPathContext: missing xpath context\n");
7910 }
7911 CODE:
7912 2 ▶ if(XPathContextDATA(ctxt)->varData != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(XPathContextDATA(ctxt)->varData != NULL) { 1 1 2
7913 1 RETVAL = newSVsv(XPathContextDATA(ctxt)->varLookup);
7914 } else {
7915 1 RETVAL = &PL_sv_undef;
7916 }
7917 OUTPUT:
7918 RETVAL
7919  
7920 void
7921 registerVarLookupFunc( pxpath_context, lookup_func, lookup_data )
7922 SV * pxpath_context
7923 SV * lookup_func
7924 SV * lookup_data
7925 PREINIT:
7926 4 xmlXPathContextPtr ctxt = NULL;
7927 4 XPathContextDataPtr data = NULL;
7928 INIT:
7929 4 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
7930 4 ▶ if ( ctxt == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) 0 4 4
7931 0 croak("XPathContext: missing xpath context\n");
7932 4 data = XPathContextDATA(ctxt);
7933 4 ▶ if ( data == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( data == NULL ) 0 4 4
7934 0 croak("XPathContext: missing xpath context private data\n");
7935 4 LibXML_configure_xpathcontext(ctxt);
7936 /* free previous lookup function and data */
7937 4 ▶ if (data->varLookup && SvOK(data->varLookup))
Branch: 2 branches
BranchTrueFalseTotal
if (data->varLookup && SvOK(data->varLookup)) 1 3 4
if (data->varLookup && SvOK(data->varLookup)) 1 0 1
7938 1 SvREFCNT_dec(data->varLookup);
7939 4 ▶ if (data->varData && SvOK(data->varData))
Branch: 2 branches
BranchTrueFalseTotal
if (data->varData && SvOK(data->varData)) 1 3 4
if (data->varData && SvOK(data->varData)) 1 0 1
7940 1 SvREFCNT_dec(data->varData);
7941 4 data->varLookup=NULL;
7942 4 data->varData=NULL;
7943 PPCODE:
7944 4 ▶ if (SvOK(lookup_func)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(lookup_func)) { 3 1 4
7945 3 ▶ if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) { 3 0 3
if ( SvROK(lookup_func) && SvTYPE(SvRV(lookup_func)) == SVt_PVCV ) { 3 0 3
7946 3 data->varLookup = newSVsv(lookup_func);
7947 3 ▶ if (SvOK(lookup_data))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(lookup_data)) 2 1 3
7948 2 data->varData = newSVsv(lookup_data);
7949 3 xmlXPathRegisterVariableLookup(ctxt,
7950 LibXML_generic_variable_lookup, ctxt);
7951 3 ▶ if (ctxt->varLookupData==NULL || ctxt->varLookupData != ctxt) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctxt->varLookupData==NULL || ctxt->varLookupData != ctxt) { 3 0 3
if (ctxt->varLookupData==NULL || ctxt->varLookupData != ctxt) { 0 3 3
7952 0 croak( "XPathContext: registration failure\n" );
7953 }
7954 } else {
7955 0 croak("XPathContext: 1st argument is not a CODE reference\n");
7956 }
7957 } else {
7958 /* unregister */
7959 1 xmlXPathRegisterVariableLookup(ctxt, NULL, NULL);
7960 }
7961  
7962 void
7963 registerFunctionNS( pxpath_context, name, uri, func)
7964 SV * pxpath_context
7965 char * name
7966 SV * uri
7967 SV * func
7968 PREINIT:
7969 18 xmlXPathContextPtr ctxt = NULL;
7970 SV * pfdr;
7971 SV * key;
7972 STRLEN len;
7973 char *strkey;
7974  
7975 INIT:
7976 18 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
7977 18 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 18 18
7978 0 croak("XPathContext: missing xpath context\n");
7979 }
7980 18 LibXML_configure_xpathcontext(ctxt);
7981 18 ▶ if ( !SvOK(func) ||
Branch: 1 branch
BranchTrueFalseTotal
if ( !SvOK(func) || 13 5 18
7982 13 ▶ (SvOK(func) && ((SvROK(func) && SvTYPE(SvRV(func)) == SVt_PVCV )
Branch: 3 branches
BranchTrueFalseTotal
(SvOK(func) && ((SvROK(func) && SvTYPE(SvRV(func)) == SVt_PVCV ) 13 0 13
(SvOK(func) && ((SvROK(func) && SvTYPE(SvRV(func)) == SVt_PVCV ) 12 1 13
(SvOK(func) && ((SvROK(func) && SvTYPE(SvRV(func)) == SVt_PVCV ) 0 12 12
7983 1 ▶ || SvPOK(func)))) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvPOK(func)))) { 1 0 1
7984 18 ▶ if (ctxt->funcLookupData == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt->funcLookupData == NULL) { 3 15 18
7985 3 ▶ if (SvOK(func)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(func)) { 3 0 3
7986 3 pfdr = newRV_noinc((SV*) newHV());
7987 3 ctxt->funcLookupData = pfdr;
7988 } else {
7989 /* looks like no perl function was never registered, */
7990 /* nothing to unregister */
7991 0 warn("XPathContext: nothing to unregister\n");
7992 0 return;
7993 }
7994 } else {
7995 15 ▶ if (SvTYPE(SvRV((SV *)ctxt->funcLookupData)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(SvRV((SV *)ctxt->funcLookupData)) == SVt_PVHV) { 15 0 15
7996 /* good, it's a HV */
7997 15 pfdr = (SV *)ctxt->funcLookupData;
7998 } else {
7999 0 croak ("XPathContext: cannot register: funcLookupData structure occupied\n");
8000 }
8001 }
8002 18 key = newSVpvn("",0);
8003 18 ▶ if (SvOK(uri)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(uri)) { 2 16 18
8004 2 sv_catpv(key, "{");
8005 2 sv_catsv(key, uri);
8006 2 sv_catpv(key, "}");
8007 }
8008 18 sv_catpv(key, (const char*)name);
8009 18 strkey = SvPV(key, len);
8010 /* warn("Trying to store function '%s' in %d\n", strkey, pfdr); */
8011 18 ▶ if (SvOK(func)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(func)) { 13 5 18
8012 13 (void) hv_store((HV *)SvRV(pfdr),strkey, len, newSVsv(func), 0);
8013 } else {
8014 /* unregister */
8015 5 (void) hv_delete((HV *)SvRV(pfdr),strkey, len, G_DISCARD);
8016 }
8017 18 SvREFCNT_dec(key);
8018 } else {
8019 0 croak("XPathContext: 3rd argument is not a CODE reference or function name\n");
8020 }
8021 PPCODE:
8022 18 ▶ if (SvOK(uri)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(uri)) { 2 16 18
8023 2 xmlXPathRegisterFuncNS(ctxt, (xmlChar *) name,
8024 2 (xmlChar *) SvPV(uri, len),
8025 2 ▶ (SvOK(func) ?
Branch: 1 branch
BranchTrueFalseTotal
(SvOK(func) ? 1 1 2
8026 LibXML_generic_extension_function : NULL));
8027 } else {
8028 16 xmlXPathRegisterFunc(ctxt, (xmlChar *) name,
8029 16 ▶ (SvOK(func) ?
Branch: 1 branch
BranchTrueFalseTotal
(SvOK(func) ? 12 4 16
8030 LibXML_generic_extension_function : NULL));
8031 }
8032  
8033 void
8034 _free_node_pool( pxpath_context )
8035 SV * pxpath_context
8036 PREINIT:
8037 130 xmlXPathContextPtr ctxt = NULL;
8038 INIT:
8039 130 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
8040 130 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 130 130
8041 0 croak("XPathContext: missing xpath context\n");
8042 }
8043 PPCODE:
8044 130 ▶ if (XPathContextDATA(ctxt)->pool != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (XPathContextDATA(ctxt)->pool != NULL) { 20 110 130
8045 20 SvREFCNT_dec((SV *)XPathContextDATA(ctxt)->pool);
8046 20 XPathContextDATA(ctxt)->pool = NULL;
8047 }
8048  
8049 void
8050 _findnodes( pxpath_context, perl_xpath )
8051 SV * pxpath_context
8052 SV * perl_xpath
8053 PREINIT:
8054 61 xmlXPathContextPtr ctxt = NULL;
8055 61 ProxyNodePtr owner = NULL;
8056 61 xmlXPathObjectPtr found = NULL;
8057 61 xmlNodeSetPtr nodelist = NULL;
8058 61 SV * element = NULL ;
8059 61 xmlChar * xpath = NULL;
8060 61 xmlXPathCompExprPtr comp = NULL;
8061 61 PREINIT_SAVED_ERROR
8062 INIT:
8063 61 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
8064 61 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 61 61
8065 0 croak("XPathContext: missing xpath context\n");
8066 }
8067 61 LibXML_configure_xpathcontext(ctxt);
8068 61 ▶ if ( ctxt->node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->node == NULL ) { 0 61 61
8069 0 croak("XPathContext: lost current node\n");
8070 }
8071 61 ▶ if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) { 4 57 61
if (sv_isobject(perl_xpath) && sv_isa(perl_xpath,"XML::LibXML::XPathExpression")) { 4 0 4
8072 4 comp = INT2PTR(xmlXPathCompExprPtr,SvIV((SV*)SvRV( perl_xpath )));
8073 4 ▶ if (!comp) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!comp) XSRETURN_UNDEF; 0 4 4
8074 } else {
8075 57 xpath = nodeSv2C(perl_xpath, ctxt->node);
8076 57 ▶ if ( !(xpath && xmlStrlen(xpath)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !(xpath && xmlStrlen(xpath)) ) { 57 0 57
if ( !(xpath && xmlStrlen(xpath)) ) { 0 57 57
8077 0 ▶ if ( xpath )
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath ) 0 0 0
8078 0 xmlFree(xpath);
8079 0 croak("XPathContext: empty XPath found\n");
8080 XSRETURN_UNDEF;
8081 }
8082 }
8083 PPCODE:
8084 61 INIT_ERROR_HANDLER;
8085  
8086 61 PUTBACK ;
8087 61 ▶ if (comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (comp) { 4 57 61
8088 4 found = domXPathCompFindCtxt( ctxt, comp, 0 );
8089 } else {
8090 57 found = domXPathFindCtxt( ctxt, xpath, 0 );
8091 57 xmlFree(xpath);
8092 }
8093 61 SPAGAIN ;
8094  
8095 61 ▶ if (found != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (found != NULL) { 59 2 61
8096 59 nodelist = found->nodesetval;
8097 } else {
8098 2 nodelist = NULL;
8099 }
8100 61 CLEANUP_ERROR_HANDLER;
8101 61 ▶ if ( nodelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist ) { 59 2 61
8102 59 REPORT_ERROR(1);
8103 59 ▶ if ( nodelist->nodeNr > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist->nodeNr > 0 ) { 59 0 59
8104 int i;
8105 59 const char * cls = "XML::LibXML::Node";
8106 xmlNodePtr tnode;
8107 59 int l = nodelist->nodeNr;
8108 3135 ▶ for( i = 0 ; i < l; i++){
Branch: 1 branch
BranchTrueFalseTotal
for( i = 0 ; i < l; i++){ 3076 59 3135
8109 /* we have to create a new instance of an objectptr.
8110 * and then place the current node into the new object.
8111 * afterwards we can push the object to the array!
8112 */
8113 3076 element = NULL;
8114 3076 tnode = nodelist->nodeTab[i];
8115 3076 ▶ if (tnode->type == XML_NAMESPACE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->type == XML_NAMESPACE_DECL) { 0 3076 3076
8116 0 xmlNsPtr newns = xmlCopyNamespace((xmlNsPtr)tnode);
8117 0 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 0 0 0
8118 0 element = NEWSV(0,0);
8119 0 cls = PmmNodeTypeName( tnode );
8120 0 element = sv_setref_pv( element,
8121 (const char *)cls,
8122 newns
8123 );
8124 }
8125 else {
8126 0 continue;
8127 }
8128 }
8129 else {
8130 3076 ▶ if (tnode->doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->doc) { 3073 3 3076
8131 3073 ▶ owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); 3073 0 3073
owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); 0 3073 3073
8132 } else {
8133 /* we try to find a known node on the ancestor axis */
8134 3 xmlNodePtr n = tnode;
8135 5 ▶ while (n && n->_private == NULL) n = n->parent;
Branch: 2 branches
BranchTrueFalseTotal
while (n && n->_private == NULL) n = n->parent; 5 0 5
while (n && n->_private == NULL) n = n->parent; 2 3 5
8136 3 ▶ if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private));
Branch: 3 branches
BranchTrueFalseTotal
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 3 0 3
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 3 0 3
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 3 0 3
8137 0 else owner = NULL; /* self contained node */
8138 }
8139 3076 element = PmmNodeToSv(tnode, owner);
8140 }
8141 3076 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 3076 3076
8142 }
8143 }
8144 /* prevent libxml2 from freeing the actual nodes */
8145 59 ▶ if (found->boolval) found->boolval=0;
Branch: 1 branch
BranchTrueFalseTotal
if (found->boolval) found->boolval=0; 0 59 59
8146 59 xmlXPathFreeObject(found);
8147 }
8148 else {
8149 2 xmlXPathFreeObject(found);
8150 2 REPORT_ERROR(0);
8151 }
8152  
8153 void
8154 _find( pxpath_context, pxpath, to_bool )
8155 SV * pxpath_context
8156 SV * pxpath
8157 int to_bool
8158 PREINIT:
8159 69 xmlXPathContextPtr ctxt = NULL;
8160 69 ProxyNodePtr owner = NULL;
8161 69 xmlXPathObjectPtr found = NULL;
8162 69 xmlNodeSetPtr nodelist = NULL;
8163 69 xmlChar * xpath = NULL;
8164 69 xmlXPathCompExprPtr comp = NULL;
8165 69 PREINIT_SAVED_ERROR
8166 INIT:
8167 69 ctxt = INT2PTR(xmlXPathContextPtr,SvIV(SvRV(pxpath_context)));
8168 69 ▶ if ( ctxt == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt == NULL ) { 0 69 69
8169 0 croak("XPathContext: missing xpath context\n");
8170 }
8171 69 LibXML_configure_xpathcontext(ctxt);
8172 69 ▶ if ( ctxt->node == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->node == NULL ) { 1 68 69
8173 1 croak("XPathContext: lost current node\n");
8174 }
8175 68 ▶ if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) { 3 65 68
if (sv_isobject(pxpath) && sv_isa(pxpath,"XML::LibXML::XPathExpression")) { 3 0 3
8176 3 comp = INT2PTR(xmlXPathCompExprPtr,SvIV((SV*)SvRV( pxpath )));
8177 3 ▶ if (!comp) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!comp) XSRETURN_UNDEF; 0 3 3
8178 } else {
8179 65 xpath = nodeSv2C(pxpath, ctxt->node);
8180 65 ▶ if ( !(xpath && xmlStrlen(xpath)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( !(xpath && xmlStrlen(xpath)) ) { 65 0 65
if ( !(xpath && xmlStrlen(xpath)) ) { 0 65 65
8181 0 ▶ if ( xpath )
Branch: 1 branch
BranchTrueFalseTotal
if ( xpath ) 0 0 0
8182 0 xmlFree(xpath);
8183 0 croak("XPathContext: empty XPath found\n");
8184 XSRETURN_UNDEF;
8185 }
8186 }
8187 PPCODE:
8188 68 INIT_ERROR_HANDLER;
8189 68 PUTBACK ;
8190 68 ▶ if (comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (comp) { 3 65 68
8191 3 found = domXPathCompFindCtxt( ctxt, comp, to_bool );
8192 } else {
8193 65 found = domXPathFindCtxt( ctxt, xpath, to_bool );
8194 64 xmlFree(xpath);
8195 }
8196 67 SPAGAIN ;
8197 67 CLEANUP_ERROR_HANDLER;
8198 67 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 59 8 67
8199 59 REPORT_ERROR(1);
8200 59 switch (found->type) {
8201 10 case XPATH_NODESET:
8202 /* return as a NodeList */
8203 /* access ->nodesetval */
8204 10 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::NodeList", 0))); 0 10 10
8205 10 nodelist = found->nodesetval;
8206 10 ▶ if ( nodelist ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist ) { 10 0 10
8207 10 ▶ if ( nodelist->nodeNr > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nodelist->nodeNr > 0 ) { 10 0 10
8208 int i;
8209 10 const char * cls = "XML::LibXML::Node";
8210 xmlNodePtr tnode;
8211 SV * element;
8212 10 int l = nodelist->nodeNr;
8213  
8214 6021 ▶ for( i = 0 ; i < l; i++){
Branch: 1 branch
BranchTrueFalseTotal
for( i = 0 ; i < l; i++){ 6011 10 6021
8215 /* we have to create a new instance of an
8216 * objectptr. and then
8217 * place the current node into the new
8218 * object. afterwards we can
8219 * push the object to the array!
8220 */
8221 6011 tnode = nodelist->nodeTab[i];
8222  
8223 /* let's be paranoid */
8224 6011 ▶ if (tnode->type == XML_NAMESPACE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->type == XML_NAMESPACE_DECL) { 0 6011 6011
8225 0 xmlNsPtr newns = xmlCopyNamespace((xmlNsPtr)tnode);
8226 0 ▶ if ( newns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newns != NULL ) { 0 0 0
8227 0 element = NEWSV(0,0);
8228 0 cls = PmmNodeTypeName( tnode );
8229 0 element = sv_setref_pv( element,
8230 (const char *)cls,
8231 (void*)newns
8232 );
8233 }
8234 else {
8235 0 continue;
8236 }
8237 }
8238 else {
8239 6011 ▶ if (tnode->doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (tnode->doc) { 6011 0 6011
8240 6011 ▶ owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc));
Branch: 2 branches
BranchTrueFalseTotal
owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); 6011 0 6011
owner = PmmOWNERPO(PmmNewNode((xmlNodePtr) tnode->doc)); 0 6011 6011
8241 } else {
8242 /* we try to find a known node on the ancestor axis */
8243 0 xmlNodePtr n = tnode;
8244 0 ▶ while (n && n->_private == NULL) n = n->parent;
Branch: 2 branches
BranchTrueFalseTotal
while (n && n->_private == NULL) n = n->parent; 0 0 0
while (n && n->_private == NULL) n = n->parent; 0 0 0
8245 0 ▶ if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private));
Branch: 3 branches
BranchTrueFalseTotal
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 0 0 0
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 0 0 0
if (n) owner = PmmOWNERPO(((ProxyNodePtr)n->_private)); 0 0 0
8246 0 else owner = NULL; /* self contained node */
8247 }
8248 6011 element = PmmNodeToSv(tnode, owner);
8249 }
8250 6011 ▶ XPUSHs( sv_2mortal(element) );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal(element) ); 0 6011 6011
8251 }
8252 }
8253 }
8254 /* prevent libxml2 from freeing the actual nodes */
8255 10 ▶ if (found->boolval) found->boolval=0;
Branch: 1 branch
BranchTrueFalseTotal
if (found->boolval) found->boolval=0; 0 10 10
8256 10 break;
8257 14 case XPATH_BOOLEAN:
8258 /* return as a Boolean */
8259 /* access ->boolval */
8260 14 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Boolean", 0))); 0 14 14
8261 14 ▶ XPUSHs(sv_2mortal(newSViv(found->boolval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(found->boolval))); 0 14 14
8262 14 break;
8263 24 case XPATH_NUMBER:
8264 /* return as a Number */
8265 /* access ->floatval */
8266 24 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Number", 0))); 0 24 24
8267 24 ▶ XPUSHs(sv_2mortal(newSVnv(found->floatval)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVnv(found->floatval))); 0 24 24
8268 24 break;
8269 11 case XPATH_STRING:
8270 /* access ->stringval */
8271 /* return as a Literal */
8272 11 ▶ XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv("XML::LibXML::Literal", 0))); 0 11 11
8273 11 ▶ XPUSHs(sv_2mortal(C2Sv(found->stringval, NULL)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(C2Sv(found->stringval, NULL))); 0 11 11
8274 11 break;
8275 0 default:
8276 0 croak("Unknown XPath return type");
8277 }
8278 59 xmlXPathFreeObject(found);
8279 }
8280 else {
8281 8 REPORT_ERROR(0);
8282 }
8283  
8284 MODULE = XML::LibXML PACKAGE = XML::LibXML::InputCallback
8285  
8286 void
8287 lib_cleanup_callbacks( self )
8288 CODE:
8289 677 xmlCleanupInputCallbacks();
8290 677 xmlRegisterDefaultInputCallbacks();
8291  
8292 void
8293 lib_init_callbacks( self )
8294 CODE:
8295 677 xmlRegisterDefaultInputCallbacks(); /* important */
8296 677 xmlRegisterInputCallbacks((xmlInputMatchCallback) LibXML_input_match,
8297 (xmlInputOpenCallback) LibXML_input_open,
8298 (xmlInputReadCallback) LibXML_input_read,
8299 (xmlInputCloseCallback) LibXML_input_close);
8300  
8301 #ifdef HAVE_READER_SUPPORT
8302  
8303 MODULE = XML::LibXML PACKAGE = XML::LibXML::Reader
8304  
8305 xmlTextReaderPtr
8306 _newForFile(CLASS, filename, encoding, options)
8307 const char* CLASS
8308 const char* filename
8309 const char * encoding = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8310 int options = SvOK($arg) ? SvIV($arg) : 0;
8311 CODE:
8312 9 RETVAL = xmlReaderForFile(filename, encoding, options);
8313 INIT_READER_ERROR_HANDLER(RETVAL);
8314 OUTPUT:
8315 RETVAL
8316  
8317 xmlTextReaderPtr
8318 _newForIO(CLASS, fh, url, encoding, options)
8319 const char* CLASS
8320 SV * fh
8321 const char * url = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8322 const char * encoding = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8323 int options = SvOK($arg) ? SvIV($arg) : 0;
8324 CODE:
8325 1 (void)SvREFCNT_inc(fh); /* _dec'd by LibXML_close_perl */
8326 1 RETVAL = xmlReaderForIO((xmlInputReadCallback) LibXML_read_perl,
8327 (xmlInputCloseCallback) LibXML_close_perl,
8328 (void *) fh, url, encoding, options);
8329 INIT_READER_ERROR_HANDLER(RETVAL)
8330 OUTPUT:
8331 RETVAL
8332  
8333 xmlTextReaderPtr
8334 _newForString(CLASS, string, url, encoding, options)
8335 const char* CLASS
8336 SV * string
8337 const char * url = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8338 const char * encoding = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8339 int options = SvOK($arg) ? SvIV($arg) : 0;
8340 CODE:
8341 19 ▶ if (encoding == NULL && SvUTF8( string )) {
Branch: 2 branches
BranchTrueFalseTotal
if (encoding == NULL && SvUTF8( string )) { 19 0 19
if (encoding == NULL && SvUTF8( string )) { 2 17 19
8342 2 encoding = "UTF-8";
8343 }
8344 19 RETVAL = xmlReaderForDoc((xmlChar* )SvPV_nolen(string), url, encoding, options);
8345 INIT_READER_ERROR_HANDLER(RETVAL)
8346 OUTPUT:
8347 RETVAL
8348  
8349 xmlTextReaderPtr
8350 _newForFd(CLASS, fd, url, encoding, options)
8351 const char* CLASS
8352 int fd
8353 const char * url = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8354 const char * encoding = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8355 int options = SvOK($arg) ? SvIV($arg) : 0;
8356 CODE:
8357 1 RETVAL = xmlReaderForFd(fd, url, encoding, options);
8358 INIT_READER_ERROR_HANDLER(RETVAL)
8359 OUTPUT:
8360 RETVAL
8361  
8362 xmlTextReaderPtr
8363 _newForDOM(CLASS, perl_doc)
8364 const char* CLASS
8365 SV * perl_doc
8366 CODE:
8367 1 PmmREFCNT_inc(SvPROXYNODE(perl_doc)); /* _dec in DESTROY */
8368 1 RETVAL = xmlReaderWalker((xmlDocPtr) PmmSvNode(perl_doc));
8369 OUTPUT:
8370 RETVAL
8371  
8372 int
8373 attributeCount(reader)
8374 xmlTextReaderPtr reader
8375 CODE:
8376 1 RETVAL = xmlTextReaderAttributeCount(reader);
8377 OUTPUT:
8378 RETVAL
8379  
8380 SV *
8381 baseURI(reader)
8382 xmlTextReaderPtr reader
8383 PREINIT:
8384 1 const xmlChar *result = NULL;
8385 CODE:
8386 1 result = xmlTextReaderConstBaseUri(reader);
8387 1 RETVAL = C2Sv(result, NULL);
8388 OUTPUT:
8389 RETVAL
8390  
8391 long
8392 byteConsumed(reader)
8393 xmlTextReaderPtr reader
8394 CODE:
8395 1 RETVAL = xmlTextReaderByteConsumed(reader);
8396 OUTPUT:
8397 RETVAL
8398  
8399 int
8400 _close(reader)
8401 xmlTextReaderPtr reader
8402 CODE:
8403 1 RETVAL = xmlTextReaderClose(reader);
8404 OUTPUT:
8405 RETVAL
8406  
8407 SV *
8408 encoding(reader)
8409 xmlTextReaderPtr reader
8410 PREINIT:
8411 1 const xmlChar *result = NULL;
8412 CODE:
8413 1 result = xmlTextReaderConstEncoding(reader);
8414 1 RETVAL = C2Sv(result, NULL);
8415 OUTPUT:
8416 RETVAL
8417  
8418 SV *
8419 localName(reader)
8420 xmlTextReaderPtr reader
8421 PREINIT:
8422 2 const xmlChar *result = NULL;
8423 CODE:
8424 2 result = xmlTextReaderConstLocalName(reader);
8425 2 RETVAL = C2Sv(result, NULL);
8426 OUTPUT:
8427 RETVAL
8428  
8429 SV *
8430 name(reader)
8431 xmlTextReaderPtr reader
8432 PREINIT:
8433 76 const xmlChar *result = NULL;
8434 CODE:
8435 76 result = xmlTextReaderConstName(reader);
8436 76 RETVAL = C2Sv(result, NULL);
8437 OUTPUT:
8438 RETVAL
8439  
8440 SV *
8441 namespaceURI(reader)
8442 xmlTextReaderPtr reader
8443 PREINIT:
8444 36 const xmlChar *result = NULL;
8445 CODE:
8446 36 result = xmlTextReaderConstNamespaceUri(reader);
8447 36 RETVAL = C2Sv(result, NULL);
8448 OUTPUT:
8449 RETVAL
8450  
8451 SV *
8452 prefix(reader)
8453 xmlTextReaderPtr reader
8454 PREINIT:
8455 2 const xmlChar *result = NULL;
8456 CODE:
8457 2 result = xmlTextReaderConstPrefix(reader);
8458 2 RETVAL = C2Sv(result, NULL);
8459 OUTPUT:
8460 RETVAL
8461  
8462 SV *
8463 value(reader)
8464 xmlTextReaderPtr reader
8465 PREINIT:
8466 29 const xmlChar *result = NULL;
8467 CODE:
8468 29 result = xmlTextReaderConstValue(reader);
8469 29 RETVAL = C2Sv(result, NULL);
8470 OUTPUT:
8471 RETVAL
8472  
8473 SV *
8474 xmlLang(reader)
8475 xmlTextReaderPtr reader
8476 PREINIT:
8477 2 const xmlChar *result = NULL;
8478 CODE:
8479 2 result = xmlTextReaderConstXmlLang(reader);
8480 2 RETVAL = C2Sv(result, NULL);
8481 OUTPUT:
8482 RETVAL
8483  
8484  
8485 SV *
8486 xmlVersion(reader)
8487 xmlTextReaderPtr reader
8488 PREINIT:
8489 1 const xmlChar *result = NULL;
8490 CODE:
8491 1 result = xmlTextReaderConstXmlVersion(reader);
8492 1 RETVAL = C2Sv(result, NULL);
8493 OUTPUT:
8494 RETVAL
8495  
8496  
8497 int
8498 depth(reader)
8499 xmlTextReaderPtr reader
8500 CODE:
8501 1 RETVAL = xmlTextReaderDepth(reader);
8502 OUTPUT:
8503 RETVAL
8504  
8505  
8506 SV *
8507 getAttribute(reader, name)
8508 xmlTextReaderPtr reader
8509 char * name
8510 PREINIT:
8511 1 xmlChar *result = NULL;
8512 CODE:
8513 1 result = xmlTextReaderGetAttribute(reader, (xmlChar*) name);
8514 1 RETVAL = C2Sv(result, NULL);
8515 1 xmlFree(result);
8516 OUTPUT:
8517 RETVAL
8518  
8519 SV *
8520 getAttributeNo(reader, no)
8521 xmlTextReaderPtr reader
8522 int no
8523 PREINIT:
8524 1 xmlChar *result = NULL;
8525 CODE:
8526 1 result = xmlTextReaderGetAttributeNo(reader, no);
8527 1 RETVAL = C2Sv(result, NULL);
8528 1 xmlFree(result);
8529 OUTPUT:
8530 RETVAL
8531  
8532 SV *
8533 getAttributeNs(reader, localName, namespaceURI)
8534 xmlTextReaderPtr reader
8535 char * localName
8536 char * namespaceURI = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8537 PREINIT:
8538 1 xmlChar *result = NULL;
8539 CODE:
8540 1 result = xmlTextReaderGetAttributeNs(reader, (xmlChar*) localName,
8541 (xmlChar*) namespaceURI);
8542 1 RETVAL = C2Sv(result, NULL);
8543 1 xmlFree(result);
8544 OUTPUT:
8545 RETVAL
8546  
8547 int
8548 columnNumber(reader)
8549 xmlTextReaderPtr reader
8550 CODE:
8551 1 RETVAL = xmlTextReaderGetParserColumnNumber(reader);
8552 OUTPUT:
8553 RETVAL
8554  
8555 int
8556 lineNumber(reader)
8557 xmlTextReaderPtr reader
8558 CODE:
8559 1 RETVAL = xmlTextReaderGetParserLineNumber(reader);
8560 OUTPUT:
8561 RETVAL
8562  
8563 int
8564 _getParserProp(reader, prop)
8565 xmlTextReaderPtr reader
8566 int prop
8567 CODE:
8568 1 RETVAL = xmlTextReaderGetParserProp(reader, prop);
8569 OUTPUT:
8570 RETVAL
8571  
8572 int
8573 hasAttributes(reader)
8574 xmlTextReaderPtr reader
8575 CODE:
8576 1 RETVAL = xmlTextReaderHasAttributes(reader);
8577 OUTPUT:
8578 RETVAL
8579  
8580 int
8581 hasValue(reader)
8582 xmlTextReaderPtr reader
8583 CODE:
8584 1 RETVAL = xmlTextReaderHasValue(reader);
8585 OUTPUT:
8586 RETVAL
8587  
8588 SV*
8589 getAttributeHash(reader)
8590 xmlTextReaderPtr reader
8591 PREINIT:
8592 HV* hv;
8593 SV* sv;
8594 const xmlChar* name;
8595 0 PREINIT_SAVED_ERROR
8596 CODE:
8597 0 INIT_ERROR_HANDLER;
8598 0 hv=newHV();
8599 0 ▶ if (xmlTextReaderHasAttributes(reader) && xmlTextReaderMoveToFirstAttribute(reader)==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (xmlTextReaderHasAttributes(reader) && xmlTextReaderMoveToFirstAttribute(reader)==1) { 0 0 0
if (xmlTextReaderHasAttributes(reader) && xmlTextReaderMoveToFirstAttribute(reader)==1) { 0 0 0
8600 do {
8601 0 name = xmlTextReaderConstName(reader);
8602 0 sv=C2Sv((xmlTextReaderConstValue(reader)),NULL);
8603 0 ▶ if (sv && hv_store(hv, (const char*) name, xmlStrlen(name), sv, 0)==NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && hv_store(hv, (const char*) name, xmlStrlen(name), sv, 0)==NULL) { 0 0 0
if (sv && hv_store(hv, (const char*) name, xmlStrlen(name), sv, 0)==NULL) { 0 0 0
8604 0 SvREFCNT_dec(sv); /* free if not needed by hv_stores */
8605 }
8606 0 ▶ } while (xmlTextReaderMoveToNextAttribute(reader)==1);
Branch: 1 branch
BranchTrueFalseTotal
} while (xmlTextReaderMoveToNextAttribute(reader)==1); 0 0 0
8607 0 xmlTextReaderMoveToElement(reader);
8608 }
8609 0 RETVAL=newRV_noinc((SV*)hv);
8610 0 CLEANUP_ERROR_HANDLER;
8611 0 REPORT_ERROR(0);
8612 OUTPUT:
8613 RETVAL
8614  
8615 int
8616 isDefault(reader)
8617 xmlTextReaderPtr reader
8618 CODE:
8619 1 RETVAL = xmlTextReaderIsDefault(reader);
8620 OUTPUT:
8621 RETVAL
8622  
8623 int
8624 isEmptyElement(reader)
8625 xmlTextReaderPtr reader
8626 CODE:
8627 1 RETVAL = xmlTextReaderIsEmptyElement(reader);
8628 OUTPUT:
8629 RETVAL
8630  
8631 int
8632 isNamespaceDecl(reader)
8633 xmlTextReaderPtr reader
8634 CODE:
8635 1 RETVAL = xmlTextReaderIsNamespaceDecl(reader);
8636 OUTPUT:
8637 RETVAL
8638  
8639 int
8640 isValid(reader)
8641 xmlTextReaderPtr reader
8642 CODE:
8643 1 RETVAL = xmlTextReaderIsValid(reader);
8644 OUTPUT:
8645 RETVAL
8646  
8647 SV *
8648 lookupNamespace(reader, prefix)
8649 xmlTextReaderPtr reader
8650 char * prefix = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8651 PREINIT:
8652 1 xmlChar *result = NULL;
8653 CODE:
8654 1 result = xmlTextReaderLookupNamespace(reader, (xmlChar*) prefix);
8655 1 RETVAL = C2Sv(result, NULL);
8656 1 xmlFree(result);
8657 OUTPUT:
8658 RETVAL
8659  
8660  
8661 int
8662 moveToAttribute(reader, name)
8663 xmlTextReaderPtr reader
8664 char * name
8665 CODE:
8666 1 RETVAL = xmlTextReaderMoveToAttribute(reader, (xmlChar*) name);
8667 OUTPUT:
8668 RETVAL
8669  
8670 int
8671 moveToAttributeNo(reader, no)
8672 xmlTextReaderPtr reader
8673 int no
8674 CODE:
8675 1 RETVAL = xmlTextReaderMoveToAttributeNo(reader, no);
8676 OUTPUT:
8677 RETVAL
8678  
8679 int
8680 moveToAttributeNs(reader, localName, namespaceURI)
8681 xmlTextReaderPtr reader
8682 char * localName
8683 char * namespaceURI = SvOK($arg) ? SvPV_nolen($arg) : NULL;
8684 CODE:
8685 1 RETVAL = xmlTextReaderMoveToAttributeNs(reader,
8686 (xmlChar*) localName, (xmlChar*) namespaceURI);
8687 OUTPUT:
8688 RETVAL
8689  
8690 int
8691 moveToElement(reader)
8692 xmlTextReaderPtr reader
8693 CODE:
8694 2 RETVAL = xmlTextReaderMoveToElement(reader);
8695 OUTPUT:
8696 RETVAL
8697  
8698 int
8699 moveToFirstAttribute(reader)
8700 xmlTextReaderPtr reader
8701 CODE:
8702 1 RETVAL = xmlTextReaderMoveToFirstAttribute(reader);
8703 OUTPUT:
8704 RETVAL
8705  
8706 int
8707 moveToNextAttribute(reader)
8708 xmlTextReaderPtr reader
8709 CODE:
8710 1 RETVAL = xmlTextReaderMoveToNextAttribute(reader);
8711 OUTPUT:
8712 RETVAL
8713  
8714 int
8715 next(reader)
8716 xmlTextReaderPtr reader
8717 PREINIT:
8718 1 PREINIT_SAVED_ERROR
8719 CODE:
8720 1 INIT_ERROR_HANDLER;
8721 1 RETVAL = xmlTextReaderNext(reader);
8722 1 CLEANUP_ERROR_HANDLER;
8723 1 REPORT_ERROR(0);
8724 OUTPUT:
8725 RETVAL
8726  
8727 #define LIBXML_READER_NEXT_SIBLING(ret,reader) \
8728 ret = xmlTextReaderNextSibling(reader); \
8729 if (ret == -1) \
8730 { \
8731 int depth; \
8732 depth = xmlTextReaderDepth(reader); \
8733 ret = xmlTextReaderRead(reader); \
8734 while (ret == 1 && xmlTextReaderDepth(reader) > depth) { \
8735 ret = xmlTextReaderNext(reader); \
8736 } \
8737 if (ret == 1) { \
8738 if (xmlTextReaderDepth(reader) != depth) { \
8739 ret = 0; \
8740 } else if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { \
8741 ret = xmlTextReaderRead(reader); \
8742 } \
8743 } \
8744 }
8745  
8746 int
8747 nextSibling(reader)
8748 xmlTextReaderPtr reader
8749 PREINIT:
8750 2 PREINIT_SAVED_ERROR
8751 CODE:
8752 2 INIT_ERROR_HANDLER;
8753 10 ▶ LIBXML_READER_NEXT_SIBLING(RETVAL,reader)
Branch: 6 branches
BranchTrueFalseTotal
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 2 0 2
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 10 0 10
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 8 2 10
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 2 0 2
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 0 2 2
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 2 0 2
8754 2 CLEANUP_ERROR_HANDLER;
8755 2 REPORT_ERROR(0);
8756 OUTPUT:
8757 RETVAL
8758  
8759 int
8760 nextSiblingElement(reader, name = NULL, nsURI = NULL)
8761 xmlTextReaderPtr reader
8762 const char * name
8763 const char * nsURI
8764 PREINIT:
8765 1 PREINIT_SAVED_ERROR
8766 CODE:
8767 1 INIT_ERROR_HANDLER;
8768 do {
8769 10 ▶ LIBXML_READER_NEXT_SIBLING(RETVAL,reader)
Branch: 6 branches
BranchTrueFalseTotal
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 6 0 6
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 10 0 10
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 4 6 10
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 6 0 6
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 0 6 6
LIBXML_READER_NEXT_SIBLING(RETVAL,reader) 1 5 6
8770 6 ▶ if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) {
Branch: 9 branches
BranchTrueFalseTotal
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 3 3 6
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 3 3
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 3 3
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 3 0 3
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 1 2 3
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 1 0 1
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 1 1
8771 break;
8772 }
8773 5 ▶ } while (RETVAL == 1);
Branch: 1 branch
BranchTrueFalseTotal
} while (RETVAL == 1); 5 0 5
8774 1 CLEANUP_ERROR_HANDLER;
8775 1 REPORT_ERROR(0);
8776 OUTPUT:
8777 RETVAL
8778  
8779 int
8780 nextElement(reader, name = NULL, nsURI = NULL)
8781 xmlTextReaderPtr reader
8782 const char * name
8783 const char * nsURI
8784 PREINIT:
8785 6 PREINIT_SAVED_ERROR
8786 CODE:
8787 6 INIT_ERROR_HANDLER;
8788 do {
8789 10 RETVAL = xmlTextReaderRead(reader);
8790 10 ▶ if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) {
Branch: 9 branches
BranchTrueFalseTotal
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 6 4 10
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 6 0 6
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 1 5 6
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 1 0 1
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 1 1
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
if (LIBXML_READER_TEST_ELEMENT(reader,name,nsURI)) { 0 0 0
8791 break;
8792 }
8793 4 ▶ } while (RETVAL == 1);
Branch: 1 branch
BranchTrueFalseTotal
} while (RETVAL == 1); 4 0 4
8794 6 CLEANUP_ERROR_HANDLER;
8795 6 REPORT_ERROR(0);
8796 OUTPUT:
8797 RETVAL
8798  
8799 int
8800 nextPatternMatch(reader, compiled)
8801 xmlTextReaderPtr reader
8802 xmlPatternPtr compiled
8803 PREINIT:
8804 5 PREINIT_SAVED_ERROR
8805 5 ▶ xmlNodePtr node = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNodePtr node = NULL; 5 0 5
8806 CODE:
8807 5 ▶ if ( compiled == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( compiled == NULL ) 0 5 5
8808 0 croak("Usage: $reader->nextPatternMatch( a-XML::LibXML::Pattern-object )");
8809 do {
8810 42 RETVAL = xmlTextReaderRead(reader);
8811 42 node = xmlTextReaderCurrentNode(reader);
8812 42 ▶ if (node && xmlPatternMatch(compiled, node)) {
Branch: 2 branches
BranchTrueFalseTotal
if (node && xmlPatternMatch(compiled, node)) { 41 1 42
if (node && xmlPatternMatch(compiled, node)) { 4 37 41
8813 4 break;
8814 }
8815 38 ▶ } while (RETVAL == 1);
Branch: 1 branch
BranchTrueFalseTotal
} while (RETVAL == 1); 37 1 38
8816 5 CLEANUP_ERROR_HANDLER;
8817 5 REPORT_ERROR(0);
8818 OUTPUT:
8819 RETVAL
8820  
8821 int
8822 skipSiblings(reader)
8823 xmlTextReaderPtr reader
8824 PREINIT:
8825 int depth;
8826 PREINIT:
8827 1 PREINIT_SAVED_ERROR
8828 CODE:
8829 1 INIT_ERROR_HANDLER;
8830 1 depth = xmlTextReaderDepth(reader);
8831 1 RETVAL = -1;
8832 1 ▶ if (depth > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (depth > 0) { 1 0 1
8833 do {
8834 3 RETVAL = xmlTextReaderNext(reader);
8835 3 ▶ } while (RETVAL == 1 && xmlTextReaderDepth(reader) >= depth);
Branch: 2 branches
BranchTrueFalseTotal
} while (RETVAL == 1 && xmlTextReaderDepth(reader) >= depth); 3 0 3
} while (RETVAL == 1 && xmlTextReaderDepth(reader) >= depth); 2 1 3
8836 1 ▶ if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) { 0 1 1
8837 0 RETVAL = -1;
8838 }
8839 }
8840 1 CLEANUP_ERROR_HANDLER;
8841 1 REPORT_ERROR(0);
8842 OUTPUT:
8843 RETVAL
8844  
8845 int
8846 nodeType(reader)
8847 xmlTextReaderPtr reader
8848 CODE:
8849 179 RETVAL = xmlTextReaderNodeType(reader);
8850 OUTPUT:
8851 RETVAL
8852  
8853 SV*
8854 quoteChar(reader)
8855 xmlTextReaderPtr reader
8856 PREINIT:
8857 int ret;
8858 CODE:
8859 0 ret = xmlTextReaderQuoteChar(reader);
8860 0 ▶ if (ret == -1) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (ret == -1) XSRETURN_UNDEF; 0 0 0
8861 0 RETVAL = newSVpvf("%c",ret);
8862 OUTPUT:
8863 RETVAL
8864  
8865 int
8866 read(reader)
8867 xmlTextReaderPtr reader
8868 PREINIT:
8869 375 PREINIT_SAVED_ERROR
8870 CODE:
8871 375 INIT_ERROR_HANDLER;
8872 375 RETVAL = xmlTextReaderRead(reader);
8873 375 CLEANUP_ERROR_HANDLER;
8874 375 REPORT_ERROR(0);
8875 OUTPUT:
8876 RETVAL
8877  
8878 int
8879 readAttributeValue(reader)
8880 xmlTextReaderPtr reader
8881 PREINIT:
8882 1 PREINIT_SAVED_ERROR
8883 CODE:
8884 1 INIT_ERROR_HANDLER;
8885 1 RETVAL = xmlTextReaderReadAttributeValue(reader);
8886 1 CLEANUP_ERROR_HANDLER;
8887 1 REPORT_ERROR(0);
8888 OUTPUT:
8889 RETVAL
8890  
8891  
8892 SV *
8893 readInnerXml(reader)
8894 xmlTextReaderPtr reader
8895 PREINIT:
8896 1 xmlChar *result = NULL;
8897 PREINIT:
8898 1 PREINIT_SAVED_ERROR
8899 CODE:
8900 1 INIT_ERROR_HANDLER;
8901 1 result = xmlTextReaderReadInnerXml(reader);
8902 1 CLEANUP_ERROR_HANDLER;
8903 1 REPORT_ERROR(0);
8904 1 ▶ if (!result) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!result) XSRETURN_UNDEF; 0 1 1
8905 1 RETVAL = C2Sv(result, NULL);
8906 1 xmlFree(result);
8907 OUTPUT:
8908 RETVAL
8909  
8910 SV *
8911 readOuterXml(reader)
8912 xmlTextReaderPtr reader
8913 PREINIT:
8914 3 xmlChar *result = NULL;
8915 PREINIT:
8916 3 PREINIT_SAVED_ERROR
8917 CODE:
8918 3 INIT_ERROR_HANDLER;
8919 3 result = xmlTextReaderReadOuterXml(reader);
8920 3 CLEANUP_ERROR_HANDLER;
8921 3 REPORT_ERROR(0);
8922 3 ▶ if (result) {
Branch: 1 branch
BranchTrueFalseTotal
if (result) { 3 0 3
8923 3 RETVAL = C2Sv(result, NULL);
8924 3 xmlFree(result);
8925 } else {
8926 0 XSRETURN_UNDEF;
8927 }
8928 OUTPUT:
8929 RETVAL
8930  
8931 int
8932 readState(reader)
8933 xmlTextReaderPtr reader
8934 CODE:
8935 1 RETVAL = xmlTextReaderReadState(reader);
8936 OUTPUT:
8937 RETVAL
8938  
8939 int
8940 _setParserProp(reader, prop, value)
8941 xmlTextReaderPtr reader
8942 int prop
8943 int value
8944 CODE:
8945 0 RETVAL = xmlTextReaderSetParserProp(reader, prop, value);
8946 OUTPUT:
8947 RETVAL
8948  
8949 int
8950 standalone(reader)
8951 xmlTextReaderPtr reader
8952 CODE:
8953 1 RETVAL = xmlTextReaderStandalone(reader);
8954 OUTPUT:
8955 RETVAL
8956  
8957 SV *
8958 _nodePath(reader)
8959 xmlTextReaderPtr reader
8960 PREINIT:
8961 8 xmlNodePtr node = NULL;
8962 8 xmlChar * path = NULL;
8963 CODE:
8964 8 node = xmlTextReaderCurrentNode(reader);
8965 8 ▶ if ( node ==NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node ==NULL ) { 0 8 8
8966 0 XSRETURN_UNDEF;
8967 }
8968 8 path = xmlGetNodePath( node );
8969 8 ▶ if ( path == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( path == NULL ) { 0 8 8
8970 0 XSRETURN_UNDEF;
8971 }
8972 8 RETVAL = C2Sv(path,NULL);
8973 8 xmlFree(path);
8974 OUTPUT:
8975 RETVAL
8976  
8977 #ifdef LIBXML_PATTERN_ENABLED
8978  
8979 int
8980 matchesPattern(reader, compiled)
8981 xmlTextReaderPtr reader
8982 xmlPatternPtr compiled
8983 PREINIT:
8984 41 ▶ xmlNodePtr node = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlNodePtr node = NULL; 41 0 41
8985 CODE:
8986 41 ▶ if ( compiled == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( compiled == NULL ) 0 41 41
8987 0 XSRETURN_UNDEF;
8988 41 node = xmlTextReaderCurrentNode(reader);
8989 41 ▶ if ( node ==NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node ==NULL ) { 0 41 41
8990 0 XSRETURN_UNDEF;
8991 }
8992 41 RETVAL = xmlPatternMatch(compiled, node);
8993 OUTPUT:
8994 RETVAL
8995  
8996 #endif /* LIBXML_PATTERN_ENABLED */
8997  
8998 SV *
8999 copyCurrentNode(reader,expand = 0)
9000 xmlTextReaderPtr reader
9001 int expand
9002 PREINIT:
9003 34 xmlNodePtr node = NULL;
9004 xmlNodePtr copy;
9005 34 xmlDocPtr doc = NULL;
9006 ProxyNodePtr proxy;
9007 PREINIT:
9008 34 PREINIT_SAVED_ERROR
9009 CODE:
9010 34 INIT_ERROR_HANDLER;
9011 34 ▶ if (expand) {
Branch: 1 branch
BranchTrueFalseTotal
if (expand) { 1 33 34
9012 1 node = xmlTextReaderExpand(reader);
9013 }
9014 else {
9015 33 node = xmlTextReaderCurrentNode(reader);
9016 }
9017 34 ▶ if (node) {
Branch: 1 branch
BranchTrueFalseTotal
if (node) { 34 0 34
9018 34 doc = xmlTextReaderCurrentDoc(reader);
9019 }
9020 34 ▶ if (!doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (!doc) { 0 34 34
9021 0 CLEANUP_ERROR_HANDLER;
9022 0 REPORT_ERROR(0);
9023 0 XSRETURN_UNDEF;
9024 }
9025 34 ▶ if (xmlTextReaderGetParserProp(reader,XML_PARSER_VALIDATE))
Branch: 1 branch
BranchTrueFalseTotal
if (xmlTextReaderGetParserProp(reader,XML_PARSER_VALIDATE)) 0 34 34
9026 0 ▶ PmmInvalidatePSVI(doc); /* the document may have psvi info */
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI(doc); /* the document may have psvi info */ 0 0 0
PmmInvalidatePSVI(doc); /* the document may have psvi info */ 0 0 0
9027  
9028 34 copy = PmmCloneNode( node, expand );
9029 34 ▶ if ( copy == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( copy == NULL ) { 0 34 34
9030 0 CLEANUP_ERROR_HANDLER;
9031 0 REPORT_ERROR(0);
9032 0 XSRETURN_UNDEF;
9033 }
9034 34 ▶ if ( copy->type == XML_DTD_NODE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( copy->type == XML_DTD_NODE ) { 0 34 34
9035 0 RETVAL = PmmNodeToSv(copy, NULL);
9036 }
9037 else {
9038 34 ProxyNodePtr docfrag = NULL;
9039  
9040 34 ▶ if ( doc != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( doc != NULL ) { 34 0 34
9041 34 xmlSetTreeDoc(copy, doc);
9042 }
9043 34 proxy = PmmNewNode((xmlNodePtr)doc);
9044 34 ▶ if (PmmREFCNT(proxy) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (PmmREFCNT(proxy) == 0) { 4 30 34
9045 4 PmmREFCNT_inc(proxy);
9046 }
9047 34 LibXML_set_reader_preserve_flag(reader);
9048  
9049 34 docfrag = PmmNewFragment( doc );
9050 34 xmlAddChild( PmmNODE(docfrag), copy );
9051 34 RETVAL = PmmNodeToSv(copy, docfrag);
9052 }
9053 34 CLEANUP_ERROR_HANDLER;
9054 34 REPORT_ERROR(0);
9055 OUTPUT:
9056 RETVAL
9057  
9058 SV *
9059 document(reader)
9060 xmlTextReaderPtr reader
9061 PREINIT:
9062 8 xmlDocPtr doc = NULL;
9063 CODE:
9064 8 doc = xmlTextReaderCurrentDoc(reader);
9065 8 ▶ if (!doc) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!doc) XSRETURN_UNDEF; 0 8 8
9066 8 RETVAL = PmmNodeToSv((xmlNodePtr)doc, NULL);
9067 /* FIXME: taint the document with PmmInvalidatePSVI if the reader did validation */
9068 8 ▶ if ( PmmREFCNT(SvPROXYNODE(RETVAL))==1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( PmmREFCNT(SvPROXYNODE(RETVAL))==1 ) { 0 8 8
9069 /* will be decremented in Reader destructor */
9070 0 PmmREFCNT_inc(SvPROXYNODE(RETVAL));
9071 }
9072 8 ▶ if (xmlTextReaderGetParserProp(reader,XML_PARSER_VALIDATE))
Branch: 1 branch
BranchTrueFalseTotal
if (xmlTextReaderGetParserProp(reader,XML_PARSER_VALIDATE)) 2 6 8
9073 2 ▶ PmmInvalidatePSVI(doc); /* the document may have psvi info */
Branch: 2 branches
BranchTrueFalseTotal
PmmInvalidatePSVI(doc); /* the document may have psvi info */ 2 0 2
PmmInvalidatePSVI(doc); /* the document may have psvi info */ 2 0 2
9074  
9075 8 LibXML_set_reader_preserve_flag(reader);
9076  
9077 OUTPUT:
9078 RETVAL
9079  
9080 int
9081 _preservePattern(reader,pattern,ns_map=NULL)
9082 xmlTextReaderPtr reader
9083 char * pattern
9084 AV * ns_map
9085 PREINIT:
9086 2 ▶ xmlChar** namespaces = NULL;
Branch: 1 branch
BranchTrueFalseTotal
xmlChar** namespaces = NULL; 2 0 2
9087 SV** aux;
9088 int last,i;
9089 CODE:
9090 2 ▶ if (ns_map) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns_map) { 1 1 2
9091 1 last = av_len(ns_map);
9092 1 New(0,namespaces, last+2, xmlChar*);
9093 3 ▶ for( i = 0; i <= last ; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for( i = 0; i <= last ; i++ ) { 2 1 3
9094 2 aux = av_fetch(ns_map,i,0);
9095 4 namespaces[i]=(xmlChar*) SvPV_nolen(*aux);
9096 }
9097 1 namespaces[i]=0;
9098 }
9099 2 RETVAL = xmlTextReaderPreservePattern(reader,(const xmlChar*) pattern,
9100 (const xmlChar**)namespaces);
9101 2 Safefree(namespaces);
9102 OUTPUT:
9103 RETVAL
9104  
9105 SV *
9106 preserveNode(reader)
9107 xmlTextReaderPtr reader
9108 PREINIT:
9109 xmlNodePtr node;
9110 xmlDocPtr doc;
9111 ProxyNodePtr proxy;
9112 20 PREINIT_SAVED_ERROR
9113 CODE:
9114 20 INIT_ERROR_HANDLER;
9115 20 doc = xmlTextReaderCurrentDoc(reader);
9116 20 ▶ if (!doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (!doc) { 0 20 20
9117 0 CLEANUP_ERROR_HANDLER;
9118 0 REPORT_ERROR(0);
9119 0 XSRETURN_UNDEF;
9120 }
9121 20 proxy = PmmNewNode((xmlNodePtr)doc);
9122 20 ▶ if ( PmmREFCNT(proxy) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( PmmREFCNT(proxy) == 0 ) { 5 15 20
9123 /* new proxy node */
9124 5 PmmREFCNT_inc(proxy);
9125 }
9126 20 LibXML_set_reader_preserve_flag(reader);
9127  
9128 20 node = xmlTextReaderPreserve(reader);
9129 20 CLEANUP_ERROR_HANDLER;
9130 20 REPORT_ERROR(0);
9131 20 ▶ if (node) {
Branch: 1 branch
BranchTrueFalseTotal
if (node) { 20 0 20
9132 20 RETVAL = PmmNodeToSv(node, proxy);
9133 } else {
9134 0 XSRETURN_UNDEF;
9135 }
9136 OUTPUT:
9137 RETVAL
9138  
9139 int
9140 finish(reader)
9141 xmlTextReaderPtr reader
9142 PREINIT:
9143 10 PREINIT_SAVED_ERROR
9144 CODE:
9145 10 INIT_ERROR_HANDLER;
9146 while (1) {
9147 102 RETVAL = xmlTextReaderRead(reader);
9148 102 ▶ if (RETVAL!=1) break;
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL!=1) break; 10 92 102
9149 }
9150 10 CLEANUP_ERROR_HANDLER;
9151 10 REPORT_ERROR(0);
9152 5 ▶ RETVAL++; /* we want 0 - fail, 1- success */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL++; /* we want 0 - fail, 1- success */ 2 3 5
9153 OUTPUT:
9154 RETVAL
9155  
9156 #ifdef HAVE_SCHEMAS
9157  
9158 int
9159 _setRelaxNGFile(reader,rng)
9160 xmlTextReaderPtr reader
9161 char* rng
9162 CODE:
9163 2 RETVAL = xmlTextReaderRelaxNGValidate(reader,rng);
9164 OUTPUT:
9165 RETVAL
9166  
9167 int
9168 _setRelaxNG(reader,rng_doc)
9169 xmlTextReaderPtr reader
9170 xmlRelaxNGPtr rng_doc
9171 CODE:
9172 2 RETVAL = xmlTextReaderRelaxNGSetSchema(reader,rng_doc);
9173 OUTPUT:
9174 RETVAL
9175  
9176 int
9177 _setXSDFile(reader,xsd)
9178 xmlTextReaderPtr reader
9179 char* xsd
9180 CODE:
9181 2 RETVAL = xmlTextReaderSchemaValidate(reader,xsd);
9182 OUTPUT:
9183 RETVAL
9184  
9185 int
9186 _setXSD(reader,xsd_doc)
9187 xmlTextReaderPtr reader
9188 xmlSchemaPtr xsd_doc
9189 CODE:
9190 2 RETVAL = xmlTextReaderSetSchema(reader,xsd_doc);
9191 OUTPUT:
9192 RETVAL
9193  
9194 #endif /* HAVE_SCHEMAS */
9195  
9196 void
9197 _DESTROY(reader)
9198 xmlTextReaderPtr reader
9199 PREINIT:
9200 xmlDocPtr doc;
9201 ProxyNodePtr proxy;
9202 /* SV * error_sv = NULL;
9203 xmlTextReaderErrorFunc f = NULL; */
9204 CODE:
9205  
9206 31 ▶ if ( LibXML_get_reader_preserve_flag(reader) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( LibXML_get_reader_preserve_flag(reader) ) { 10 21 31
9207 10 doc = xmlTextReaderCurrentDoc(reader);
9208 10 ▶ if (doc) {
Branch: 1 branch
BranchTrueFalseTotal
if (doc) { 10 0 10
9209 10 proxy = PmmNewNode((xmlNodePtr)doc);
9210 10 ▶ if ( PmmREFCNT(proxy) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( PmmREFCNT(proxy) == 0 ) { 0 10 10
9211 0 PmmREFCNT_inc(proxy);
9212 }
9213 10 PmmREFCNT_dec(proxy);
9214 }
9215 }
9216 31 ▶ if (xmlTextReaderReadState(reader) != XML_TEXTREADER_MODE_CLOSED) {
Branch: 1 branch
BranchTrueFalseTotal
if (xmlTextReaderReadState(reader) != XML_TEXTREADER_MODE_CLOSED) { 30 1 31
9217 30 xmlTextReaderClose(reader);
9218 }
9219 /* xmlTextReaderGetErrorHandler(reader, &f, (void **) &error_sv);
9220 if (error_sv) {
9221 sv_2mortal(error_sv);
9222 } */
9223 31 xmlFreeTextReader(reader);
9224  
9225 #endif /* HAVE_READER_SUPPORT */
9226  
9227 #ifdef WITH_SERRORS
9228  
9229 MODULE = XML::LibXML PACKAGE = XML::LibXML::LibError
9230  
9231 int
9232 domain( self )
9233 xmlErrorPtr self
9234 CODE:
9235 338 ▶ RETVAL = self->domain;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->domain; 318 20 338
9236 OUTPUT:
9237 RETVAL
9238  
9239 int
9240 code( self )
9241 xmlErrorPtr self
9242 CODE:
9243 338 ▶ RETVAL = self->code;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->code; 318 20 338
9244 OUTPUT:
9245 RETVAL
9246  
9247 int
9248 line( self )
9249 xmlErrorPtr self
9250 CODE:
9251 338 ▶ RETVAL = self->line;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->line; 318 20 338
9252 OUTPUT:
9253 RETVAL
9254  
9255 int
9256 num1( self )
9257 xmlErrorPtr self
9258 ALIAS:
9259 int1 = 1
9260 CODE:
9261 PERL_UNUSED_VAR(ix);
9262 338 ▶ RETVAL = self->int1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->int1; 318 20 338
9263 OUTPUT:
9264 RETVAL
9265  
9266 int
9267 num2( self )
9268 xmlErrorPtr self
9269 ALIAS:
9270 int2 = 1
9271 CODE:
9272 PERL_UNUSED_VAR(ix);
9273 338 ▶ RETVAL = self->int2;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->int2; 318 20 338
9274 OUTPUT:
9275 RETVAL
9276  
9277 int
9278 level( self )
9279 xmlErrorPtr self
9280 CODE:
9281 338 ▶ RETVAL = (int)self->level;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)self->level; 318 20 338
9282 OUTPUT:
9283 RETVAL
9284  
9285 char *
9286 message( self )
9287 xmlErrorPtr self
9288 CODE:
9289 338 RETVAL = self->message;
9290 OUTPUT:
9291 RETVAL
9292  
9293 char *
9294 file( self )
9295 xmlErrorPtr self
9296 CODE:
9297 338 RETVAL = (char*)self->file;
9298 OUTPUT:
9299 RETVAL
9300  
9301 char *
9302 str1( self )
9303 xmlErrorPtr self
9304 CODE:
9305 338 RETVAL = (char*)self->str1;
9306 OUTPUT:
9307 RETVAL
9308  
9309 char *
9310 str2( self )
9311 xmlErrorPtr self
9312 CODE:
9313 338 RETVAL = (char*)self->str2;
9314 OUTPUT:
9315 RETVAL
9316  
9317 char *
9318 str3( self )
9319 xmlErrorPtr self
9320 CODE:
9321 338 RETVAL = (char*)self->str3;
9322 OUTPUT:
9323 RETVAL
9324  
9325 void
9326 context_and_column( self )
9327 xmlErrorPtr self
9328 PREINIT:
9329 xmlParserInputPtr input;
9330 const xmlChar *cur, *base, *col_cur;
9331 unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
9332 xmlChar content[81]; /* space for 80 chars + line terminator */
9333 xmlChar *ctnt;
9334 int domain;
9335 338 xmlParserCtxtPtr ctxt = NULL;
9336 PPCODE:
9337 338 domain = self->domain;
9338 338 ▶ if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
Branch: 3 branches
BranchTrueFalseTotal
if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || 93 245 338
if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || 91 2 93
if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || 89 2 91
9339 89 ▶ (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
Branch: 2 branches
BranchTrueFalseTotal
(domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || 88 1 89
(domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || 76 12 88
9340 76 ▶ (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
Branch: 1 branch
BranchTrueFalseTotal
(domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { 17 59 76
9341 279 ctxt = (xmlParserCtxtPtr) self->ctxt;
9342 }
9343 338 ▶ if (ctxt == NULL) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (ctxt == NULL) XSRETURN_EMPTY; 61 277 338
9344 277 input = ctxt->input;
9345 277 ▶ if ((input != NULL) && (input->filename == NULL) &&
Branch: 2 branches
BranchTrueFalseTotal
if ((input != NULL) && (input->filename == NULL) && 271 6 277
if ((input != NULL) && (input->filename == NULL) && 28 243 271
9346 28 ▶ (ctxt->inputNr > 1)) {
Branch: 1 branch
BranchTrueFalseTotal
(ctxt->inputNr > 1)) { 1 27 28
9347 1 input = ctxt->inputTab[ctxt->inputNr - 2];
9348 }
9349 277 ▶ if (input == NULL) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (input == NULL) XSRETURN_EMPTY; 6 271 277
9350 271 cur = input->cur;
9351 271 base = input->base;
9352 /* skip backwards over any end-of-lines */
9353 281 ▶ while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
Branch: 3 branches
BranchTrueFalseTotal
while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { 277 4 281
while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { 10 267 277
while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { 0 267 267
9354 10 cur--;
9355 }
9356 271 n = 0;
9357 /* search backwards for beginning-of-line (to max buff size) */
9358 8813 ▶ while ((n++ < (sizeof(content)-1)) && (cur > base) &&
Branch: 1 branch
BranchTrueFalseTotal
while ((n++ < (sizeof(content)-1)) && (cur > base) && 8426 116 8542
9359 17003 ▶ (*(cur) != '\n') && (*(cur) != '\r'))
Branch: 3 branches
BranchTrueFalseTotal
(*(cur) != '\n') && (*(cur) != '\r')) 8542 35 8577
(*(cur) != '\n') && (*(cur) != '\r')) 8306 120 8426
(*(cur) != '\n') && (*(cur) != '\r')) 8306 0 8306
9360 8306 cur--;
9361 /* search backwards for beginning-of-line for calculating the
9362 * column. */
9363 271 col_cur = cur;
9364 19442 ▶ while ((col_cur > base) && (*(col_cur) != '\n') && (*(col_cur) != '\r'))
Branch: 3 branches
BranchTrueFalseTotal
while ((col_cur > base) && (*(col_cur) != '\n') && (*(col_cur) != '\r')) 19303 139 19442
while ((col_cur > base) && (*(col_cur) != '\n') && (*(col_cur) != '\r')) 19171 132 19303
while ((col_cur > base) && (*(col_cur) != '\n') && (*(col_cur) != '\r')) 19171 0 19171
9365 19171 col_cur--;
9366 271 ▶ if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
Branch: 2 branches
BranchTrueFalseTotal
if ((*(cur) == '\n') || (*(cur) == '\r')) cur++; 151 120 271
if ((*(cur) == '\n') || (*(cur) == '\r')) cur++; 0 151 151
9367 271 ▶ if ((*(col_cur) == '\n') || (*(col_cur) == '\r')) col_cur++;
Branch: 2 branches
BranchTrueFalseTotal
if ((*(col_cur) == '\n') || (*(col_cur) == '\r')) col_cur++; 139 132 271
if ((*(col_cur) == '\n') || (*(col_cur) == '\r')) col_cur++; 0 139 139
9368 /* calculate the error position in terms of the current position */
9369 271 col = input->cur - col_cur;
9370 /* search forward for end-of-line (to max buff size) */
9371 271 n = 0;
9372 271 ctnt = content;
9373 /* copy selected text to our buffer */
9374 12780 ▶ while ((*cur != 0) && (*(cur) != '\n') &&
Branch: 1 branch
BranchTrueFalseTotal
while ((*cur != 0) && (*(cur) != '\n') && 12465 44 12509
9375 25099 ▶ (*(cur) != '\r') && (n < sizeof(content)-1)) {
Branch: 3 branches
BranchTrueFalseTotal
(*(cur) != '\r') && (n < sizeof(content)-1)) { 12509 125 12634
(*(cur) != '\r') && (n < sizeof(content)-1)) { 12465 0 12465
(*(cur) != '\r') && (n < sizeof(content)-1)) { 12363 102 12465
9376 12363 *ctnt++ = *cur++;
9377 12363 n++;
9378 }
9379 271 *ctnt = 0;
9380 271 ▶ EXTEND(SP,2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,2); 0 271 271
9381 271 PUSHs(sv_2mortal(C2Sv(content, NULL)));
9382 271 PUSHs(sv_2mortal(newSViv(col)));
9383  
9384 #endif /* WITH_SERRORS */
9385  
9386  
9387 #ifdef LIBXML_PATTERN_ENABLED
9388  
9389 MODULE = XML::LibXML PACKAGE = XML::LibXML::Pattern
9390  
9391 xmlPatternPtr
9392 _compilePattern(CLASS, ppattern, pattern_type, ns_map=NULL)
9393 SV * ppattern
9394 AV * ns_map
9395 int pattern_type
9396 PREINIT:
9397 1 xmlChar * pattern = Sv2C(ppattern, NULL);
9398 1 xmlChar** namespaces = NULL;
9399 SV** aux;
9400 int last,i;
9401 1 PREINIT_SAVED_ERROR
9402 CODE:
9403 1 ▶ if ( pattern == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( pattern == NULL ) 0 1 1
9404 0 XSRETURN_UNDEF;
9405 1 ▶ if (ns_map) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns_map) { 1 0 1
9406 1 last = av_len(ns_map);
9407 1 New(0,namespaces, last+2, xmlChar*);
9408 3 ▶ for( i = 0; i <= last ; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for( i = 0; i <= last ; i++ ) { 2 1 3
9409 2 aux = av_fetch(ns_map,i,0);
9410 4 namespaces[i]=(xmlChar*) SvPV_nolen(*aux);
9411 }
9412 1 namespaces[i]=0;
9413 }
9414 1 INIT_ERROR_HANDLER;
9415 1 RETVAL = xmlPatterncompile(pattern, NULL, pattern_type, (const xmlChar **) namespaces);
9416 1 Safefree(namespaces);
9417 1 xmlFree( pattern );
9418 1 CLEANUP_ERROR_HANDLER;
9419 1 REPORT_ERROR(0);
9420 1 ▶ if ( RETVAL == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == NULL ) { 0 1 1
9421 0 croak("Compilation of pattern failed");
9422 }
9423 OUTPUT:
9424 RETVAL
9425  
9426 int
9427 matchesNode(self, node)
9428 xmlPatternPtr self
9429 xmlNodePtr node
9430 CODE:
9431 34 ▶ if ( node ==NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( node ==NULL ) { 0 34 34
9432 0 XSRETURN_UNDEF;
9433 }
9434 34 RETVAL = xmlPatternMatch(self, node);
9435 OUTPUT:
9436 RETVAL
9437  
9438 void
9439 DESTROY( self )
9440 xmlPatternPtr self
9441 CODE:
9442 xs_warn( "DESTROY PATTERN OBJECT" );
9443 1 xmlFreePattern(self);
9444  
9445 #endif /* LIBXML_PATTERN_ENABLED */
9446  
9447 #ifdef LIBXML_REGEXP_ENABLED
9448  
9449 MODULE = XML::LibXML PACKAGE = XML::LibXML::RegExp
9450  
9451 xmlRegexpPtr
9452 _compile(CLASS, pregexp)
9453 SV * pregexp
9454 PREINIT:
9455 3 xmlChar * regexp = Sv2C(pregexp, NULL);
9456 3 PREINIT_SAVED_ERROR
9457 CODE:
9458 3 ▶ if ( regexp == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( regexp == NULL ) 0 3 3
9459 0 XSRETURN_UNDEF;
9460 3 INIT_ERROR_HANDLER;
9461 3 RETVAL = xmlRegexpCompile(regexp);
9462 3 xmlFree( regexp );
9463 3 CLEANUP_ERROR_HANDLER;
9464 3 REPORT_ERROR(0);
9465 2 ▶ if ( RETVAL == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == NULL ) { 0 2 2
9466 0 croak("Compilation of regexp failed");
9467 }
9468 OUTPUT:
9469 RETVAL
9470  
9471 int
9472 matches(self, pvalue)
9473 xmlRegexpPtr self
9474 SV* pvalue
9475 PREINIT:
9476 8 xmlChar * value = Sv2C(pvalue, NULL);
9477 CODE:
9478 8 ▶ if ( value == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( value == NULL ) 0 8 8
9479 0 XSRETURN_UNDEF;
9480 8 RETVAL = xmlRegexpExec(self,value);
9481 8 xmlFree( value );
9482 OUTPUT:
9483 RETVAL
9484  
9485 int
9486 isDeterministic(self)
9487 xmlRegexpPtr self
9488 CODE:
9489 2 RETVAL = xmlRegexpIsDeterminist(self);
9490 OUTPUT:
9491 RETVAL
9492  
9493 void
9494 DESTROY( self )
9495 xmlRegexpPtr self
9496 CODE:
9497 xs_warn( "DESTROY REGEXP OBJECT" );
9498 2 xmlRegFreeRegexp(self);
9499  
9500 #endif /* LIBXML_REGEXP_ENABLED */
9501  
9502  
9503 MODULE = XML::LibXML PACKAGE = XML::LibXML::XPathExpression
9504  
9505 xmlXPathCompExprPtr
9506 new(CLASS, pxpath)
9507 SV * pxpath
9508 PREINIT:
9509 10 xmlChar * xpath = Sv2C(pxpath, NULL);
9510 10 PREINIT_SAVED_ERROR
9511 CODE:
9512 10 ▶ if ( pxpath == NULL )
Branch: 1 branch
BranchTrueFalseTotal
if ( pxpath == NULL ) 0 10 10
9513 0 XSRETURN_UNDEF;
9514 10 INIT_ERROR_HANDLER;
9515 10 RETVAL = xmlXPathCompile( xpath );
9516 10 xmlFree( xpath );
9517 10 CLEANUP_ERROR_HANDLER;
9518 10 REPORT_ERROR(0);
9519 10 ▶ if ( RETVAL == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == NULL ) { 0 10 10
9520 0 croak("Compilation of XPath expression failed!");
9521 }
9522 OUTPUT:
9523 RETVAL
9524  
9525 void
9526 DESTROY( self )
9527 xmlXPathCompExprPtr self
9528 CODE:
9529 xs_warn( "DESTROY COMPILED XPATH OBJECT" );
9530 10 xmlXPathFreeCompExpr(self);
9531  
9532 MODULE = XML::LibXML PACKAGE = XML::LibXML::Common
9533  
9534 PROTOTYPES: DISABLE
9535  
9536 SV*
9537 encodeToUTF8( encoding, string )
9538 const char * encoding
9539 SV * string
9540 PREINIT:
9541 17 xmlChar * realstring = NULL;
9542 17 xmlChar * tstr = NULL;
9543 17 xmlCharEncoding enc = 0;
9544 17 STRLEN len = 0;
9545 17 xmlBufferPtr in = NULL, out = NULL;
9546 17 xmlCharEncodingHandlerPtr coder = NULL;
9547 17 PREINIT_SAVED_ERROR
9548 CODE:
9549 17 ▶ if (!SvOK(string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(string)) { 1 16 17
9550 2 XSRETURN_UNDEF;
9551 16 ▶ } else if (!SvCUR(string)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (!SvCUR(string)) { 1 15 16
9552 1 XSRETURN_PV("");
9553 }
9554 15 realstring = (xmlChar*) SvPV(string, len);
9555 15 ▶ if ( realstring != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( realstring != NULL ) { 15 0 15
9556 /* warn("encode %s", realstring ); */
9557 #ifdef HAVE_UTF8
9558 15 ▶ if ( !DO_UTF8(string) && encoding != NULL ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( !DO_UTF8(string) && encoding != NULL ) { 0 15 15
if ( !DO_UTF8(string) && encoding != NULL ) { 0 0 0
if ( !DO_UTF8(string) && encoding != NULL ) { 15 0 15
9559 #else
9560 if ( encoding != NULL ) {
9561 #endif
9562 15 enc = xmlParseCharEncoding( encoding );
9563  
9564 15 ▶ if ( enc == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc == 0 ) { 0 15 15
9565 /* this happens if the encoding is "" or NULL */
9566 0 enc = XML_CHAR_ENCODING_UTF8;
9567 }
9568  
9569 15 ▶ if ( enc == XML_CHAR_ENCODING_UTF8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc == XML_CHAR_ENCODING_UTF8 ) { 4 11 15
9570 /* copy the string */
9571 /* warn( "simply copy the string" ); */
9572 4 tstr = xmlStrndup( realstring, len );
9573 }
9574 else {
9575 11 INIT_ERROR_HANDLER;
9576 11 ▶ if ( enc > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc > 1 ) { 10 1 11
9577 10 coder= xmlGetCharEncodingHandler( enc );
9578 }
9579 1 ▶ else if ( enc == XML_CHAR_ENCODING_ERROR ){
Branch: 1 branch
BranchTrueFalseTotal
else if ( enc == XML_CHAR_ENCODING_ERROR ){ 1 0 1
9580 1 coder =xmlFindCharEncodingHandler( encoding );
9581 }
9582 else {
9583 0 croak("no encoder found\n");
9584 }
9585 11 ▶ if ( coder == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( coder == NULL ) { 1 10 11
9586 1 croak( "cannot encode string" );
9587 }
9588 10 in = xmlBufferCreateStatic((void*)realstring, len );
9589 10 out = xmlBufferCreate();
9590 10 ▶ if ( xmlCharEncInFunc( coder, out, in ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlCharEncInFunc( coder, out, in ) >= 0 ) { 10 0 10
9591 10 tstr = xmlStrdup( out->content );
9592 }
9593  
9594 10 xmlBufferFree( in );
9595 10 xmlBufferFree( out );
9596 10 xmlCharEncCloseFunc( coder );
9597  
9598 10 CLEANUP_ERROR_HANDLER;
9599 10 REPORT_ERROR(0);
9600 }
9601 }
9602 else {
9603 0 tstr = xmlStrndup( realstring, len );
9604 }
9605  
9606 14 ▶ if ( !tstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !tstr ) { 0 14 14
9607 0 croak( "return value missing!" );
9608 }
9609  
9610 14 len = xmlStrlen( tstr );
9611 14 RETVAL = newSVpvn( (const char *)tstr, len );
9612 #ifdef HAVE_UTF8
9613 14 SvUTF8_on(RETVAL);
9614 #endif
9615 14 xmlFree(tstr);
9616 }
9617 else {
9618 0 XSRETURN_UNDEF;
9619 }
9620 OUTPUT:
9621 RETVAL
9622  
9623 SV*
9624 decodeFromUTF8( encoding, string )
9625 const char * encoding
9626 SV* string
9627 PREINIT:
9628 9 xmlChar * tstr = NULL;
9629 9 xmlChar * realstring = NULL;
9630 9 xmlCharEncoding enc = 0;
9631 9 STRLEN len = 0;
9632 9 xmlBufferPtr in = NULL, out = NULL;
9633 9 xmlCharEncodingHandlerPtr coder = NULL;
9634 9 PREINIT_SAVED_ERROR
9635 CODE:
9636 #ifdef HAVE_UTF8
9637 9 ▶ if ( !SvOK(string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !SvOK(string) ) { 1 8 9
9638 2 XSRETURN_UNDEF;
9639 8 ▶ } else if (!SvCUR(string)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (!SvCUR(string)) { 1 7 8
9640 1 XSRETURN_PV("");
9641 7 ▶ } else if ( !SvUTF8(string) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( !SvUTF8(string) ) { 0 7 7
9642 0 croak("string is not utf8!!");
9643 } else {
9644 #endif
9645 7 realstring = (xmlChar*) SvPV(string, len);
9646 7 ▶ if ( realstring != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( realstring != NULL ) { 7 0 7
9647 /* warn("decode %s", realstring ); */
9648 7 enc = xmlParseCharEncoding( encoding );
9649 7 ▶ if ( enc == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc == 0 ) { 0 7 7
9650 /* this happens if the encoding is "" or NULL */
9651 0 enc = XML_CHAR_ENCODING_UTF8;
9652 }
9653  
9654 7 ▶ if ( enc == XML_CHAR_ENCODING_UTF8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc == XML_CHAR_ENCODING_UTF8 ) { 1 6 7
9655 /* copy the string */
9656 /* warn( "simply copy the string" ); */
9657 1 tstr = xmlStrdup( realstring );
9658 1 len = xmlStrlen( tstr );
9659 }
9660 else {
9661 6 INIT_ERROR_HANDLER;
9662 6 ▶ if ( enc > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc > 1 ) { 6 0 6
9663 6 coder= xmlGetCharEncodingHandler( enc );
9664 }
9665 0 ▶ else if ( enc == XML_CHAR_ENCODING_ERROR ){
Branch: 1 branch
BranchTrueFalseTotal
else if ( enc == XML_CHAR_ENCODING_ERROR ){ 0 0 0
9666 0 coder = xmlFindCharEncodingHandler( encoding );
9667 }
9668 else {
9669 0 croak("no encoder found\n");
9670 }
9671  
9672 6 ▶ if ( coder == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( coder == NULL ) { 0 6 6
9673 0 croak( "cannot encode string" );
9674 }
9675  
9676 6 in = xmlBufferCreate();
9677 6 out = xmlBufferCreate();
9678 6 xmlBufferCCat( in, (char*) realstring );
9679 6 ▶ if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) { 6 0 6
9680 6 len = xmlBufferLength( out );
9681 6 tstr = xmlCharStrndup( (char*) xmlBufferContent( out ), len );
9682 }
9683  
9684 6 xmlBufferFree( in );
9685 6 xmlBufferFree( out );
9686 6 xmlCharEncCloseFunc( coder );
9687 6 CLEANUP_ERROR_HANDLER;
9688 6 REPORT_ERROR(0);
9689 6 ▶ if ( !tstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !tstr ) { 0 6 6
9690 0 croak( "return value missing!" );
9691 }
9692 }
9693  
9694 7 RETVAL = newSVpvn( (const char *)tstr, len );
9695 7 xmlFree( tstr );
9696 #ifdef HAVE_UTF8
9697 7 ▶ if ( enc == XML_CHAR_ENCODING_UTF8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( enc == XML_CHAR_ENCODING_UTF8 ) { 1 6 7
9698 1 SvUTF8_on(RETVAL);
9699 }
9700 #endif
9701 }
9702 else {
9703 0 XSRETURN_UNDEF;
9704 }
9705 #ifdef HAVE_UTF8
9706 }
9707 #endif
9708 OUTPUT:
9709 RETVAL
« dom.c ↑ Summary perl-libxml-mm.c »