LibXML.xs

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