Module: LibXML::XML

Defined in:
lib/libxml/ns.rb,
lib/libxml/attr.rb,
lib/libxml/node.rb,
lib/libxml/tree.rb,
lib/libxml/error.rb,
lib/libxml/parser.rb,
lib/libxml/reader.rb,
lib/libxml/document.rb,
lib/libxml/attr_decl.rb,
lib/libxml/namespace.rb,
lib/libxml/attributes.rb,
lib/libxml/namespaces.rb,
lib/libxml/properties.rb,
lib/libxml/sax_parser.rb,
lib/libxml/html_parser.rb,
lib/libxml/xpath_object.rb,
lib/libxml/sax_callbacks.rb,
ext/libxml/ruby_xml.c

Defined Under Namespace

Modules: Encoding, XPath Classes: Attr, AttrDecl, Attributes, Document, Dtd, Error, HTMLParser, InputCallbacks, NS, Namespace, Namespaces, Node, Parser, Reader, RelaxNG, SaxParser, Schema, Tree, XInclude, XPointer

Constant Summary collapse

LIBXML_VERSION =

Constants

rb_str_new2(LIBXML_DOTTED_VERSION)
VERSION =
rb_str_new2(RUBY_LIBXML_VERSION)
VERNUM =
INT2NUM(RUBY_LIBXML_VERNUM)
XML_NAMESPACE =
rb_str_new2((const char*) XML_XML_NAMESPACE)

Class Method Summary collapse

Class Method Details

.catalog_dumptrue

Dump all the global catalog content stdout.

Returns:

  • (true)


12
13
14
15
16
# File 'ext/libxml/ruby_xml.c', line 12

static VALUE rxml_catalog_dump(VALUE self)
{
  xmlCatalogDump(stdout);
  return (Qtrue);
}

.catalog_remove(catalog) ⇒ true

Remove the specified resource catalog.

Returns:

  • (true)


24
25
26
27
28
29
# File 'ext/libxml/ruby_xml.c', line 24

static VALUE rxml_catalog_remove(VALUE self, VALUE cat)
{
  Check_Type(cat, T_STRING);
  xmlCatalogRemove((xmlChar *) StringValuePtr(cat));
  return (Qtrue);
}

.check_lib_versionstrue

Check LIBXML version matches version the bindings were compiled to. Throws an exception if not.

Returns:

  • (true)


38
39
40
41
42
# File 'ext/libxml/ruby_xml.c', line 38

static VALUE rxml_check_lib_versions(VALUE klass)
{
  xmlCheckVersion(LIBXML_VERSION);
  return (Qtrue);
}

.debug_entitiesObject

Determine whether included-entity debugging is enabled. (Requires Libxml to be compiled with debugging support)



336
337
338
339
340
341
342
343
344
345
346
347
# File 'ext/libxml/ruby_xml.c', line 336

static VALUE rxml_debug_entities_get(VALUE klass)
{
#ifdef LIBXML_DEBUG_ENABLED
  if (xmlParserDebugEntities)
  return(Qtrue);
  else
  return(Qfalse);
#else
  rb_warn("libxml was compiled with debugging turned off");
  return (Qfalse);
#endif
}

.debug_entities=(true) ⇒ Object

Enable or disable included-entity debugging. (Requires Libxml to be compiled with debugging support)



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'ext/libxml/ruby_xml.c', line 356

static VALUE rxml_debug_entities_set(VALUE klass, VALUE bool)
{
#ifdef LIBXML_DEBUG_ENABLED
  if (TYPE(bool) == T_FALSE)
  {
    xmlParserDebugEntities = 0;
    return(Qfalse);
  }
  else
  {
    xmlParserDebugEntities = 1;
    return(Qtrue);
  }
#else
  rb_warn("libxml was compiled with debugging turned off");
#endif
}

.default_compressionObject

Determine whether parsers use Zlib compression by default (requires libxml to be compiled with Zlib support).



691
692
693
694
695
696
697
698
699
# File 'ext/libxml/ruby_xml.c', line 691

static VALUE rxml_default_compression_get(VALUE klass)
{
#ifdef HAVE_ZLIB_H
  return(INT2FIX(xmlGetCompressMode()));
#else
  rb_warn("libxml was compiled without zlib support");
  return (Qfalse);
#endif
}

.default_compression=(true) ⇒ Object

Controls whether parsers use Zlib compression by default (requires libxml to be compiled with Zlib support).



708
709
710
711
712
713
714
715
716
717
718
# File 'ext/libxml/ruby_xml.c', line 708

static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
{
#ifdef HAVE_ZLIB_H
  Check_Type(num, T_FIXNUM);
  xmlSetCompressMode(FIX2INT(num));
  return(num);
#else
  rb_warn("libxml was compiled without zlib support");
  return (Qfalse);
#endif
}

.default_keep_blanksObject

Determine whether parsers retain whitespace by default.



380
381
382
383
384
385
386
# File 'ext/libxml/ruby_xml.c', line 380

static VALUE rxml_default_keep_blanks_get(VALUE klass)
{
  if (xmlKeepBlanksDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_keep_blanks=(true) ⇒ Object

Controls whether parsers retain whitespace by default.



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'ext/libxml/ruby_xml.c', line 394

static VALUE rxml_default_keep_blanks_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_FALSE)
  {
    xmlKeepBlanksDefaultValue = 0;
    return (Qfalse);
  }
  else if (TYPE(bool) == T_TRUE)
  {
    xmlKeepBlanksDefaultValue = 1;
    return (Qtrue);
  }
  else
  {
    rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
  }
}

.default_line_numbersObject

Determine whether parsers retain line-numbers by default.



452
453
454
455
456
457
458
# File 'ext/libxml/ruby_xml.c', line 452

static VALUE rxml_default_line_numbers_get(VALUE klass)
{
  if (xmlLineNumbersDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_line_numbers=(true) ⇒ Object

Controls whether parsers retain line-numbers by default.



466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'ext/libxml/ruby_xml.c', line 466

static VALUE rxml_default_line_numbers_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_FALSE)
  {
    xmlLineNumbersDefault(0);
    return (Qfalse);
  }
  else
  {
    xmlLineNumbersDefault(1);
    return (Qtrue);
  }
}

.default_load_external_dtdObject

Determine whether parsers load external DTDs by default.



418
419
420
421
422
423
424
# File 'ext/libxml/ruby_xml.c', line 418

static VALUE rxml_default_load_external_dtd_get(VALUE klass)
{
  if (xmlLoadExtDtdDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_load_external_dtd=(true) ⇒ Object

Controls whether parsers load external DTDs by default.



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'ext/libxml/ruby_xml.c', line 432

static VALUE rxml_default_load_external_dtd_set(VALUE klass, VALUE bool)
{
  if (bool == Qfalse)
  {
    xmlLoadExtDtdDefaultValue = 0;
    return (Qfalse);
  }
  else
  {
    xmlLoadExtDtdDefaultValue = 1;
    return (Qtrue);
  }
}

.default_optionsInteger

Returns an integer that summarize libxml2’s default options.

Returns:

  • (Integer)


511
512
513
514
515
# File 'ext/libxml/ruby_xml.c', line 511

static VALUE rxml_default_options_get(VALUE klass)
{
  int options = rxml_libxml_default_options();
  return INT2NUM(options);
}

.default_pedantic_parserObject

Determine whether parsers are pedantic by default.



523
524
525
526
527
528
529
# File 'ext/libxml/ruby_xml.c', line 523

static VALUE rxml_default_pedantic_parser_get(VALUE klass)
{
  if (xmlPedanticParserDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_pedantic_parser=(true) ⇒ Object

Controls whether parsers are pedantic by default.



537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'ext/libxml/ruby_xml.c', line 537

static VALUE rxml_default_pedantic_parser_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_FALSE)
  {
    xmlPedanticParserDefault(0);
    return (Qfalse);
  }
  else
  {
    xmlPedanticParserDefault(1);
    return (Qtrue);
  }
}

.default_substitute_entitiesObject

Determine whether parsers perform inline entity substitution (for external entities) by default.



558
559
560
561
562
563
564
# File 'ext/libxml/ruby_xml.c', line 558

static VALUE rxml_default_substitute_entities_get(VALUE klass)
{
  if (xmlSubstituteEntitiesDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_substitute_entities=(true) ⇒ Object

Controls whether parsers perform inline entity substitution (for external entities) by default.



573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'ext/libxml/ruby_xml.c', line 573

static VALUE rxml_default_substitute_entities_set(VALUE klass, VALUE bool)
{
  if (bool == Qfalse)
  {
    xmlSubstituteEntitiesDefault(0);
    return (Qfalse);
  }
  else
  {
    xmlSubstituteEntitiesDefault(1);
    return (Qtrue);
  }
}

.default_tree_indent_stringObject

Obtain the default string used by parsers to indent the XML tree for output.



594
595
596
597
598
599
600
# File 'ext/libxml/ruby_xml.c', line 594

static VALUE rxml_default_tree_indent_string_get(VALUE klass)
{
  if (xmlTreeIndentString == NULL)
    return (Qnil);
  else
    return (rb_str_new2(xmlTreeIndentString));
}

.default_tree_indent_string=(string) ⇒ Object

Set the default string used by parsers to indent the XML tree for output.



609
610
611
612
613
614
# File 'ext/libxml/ruby_xml.c', line 609

static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
{
  Check_Type(string, T_STRING);
  xmlTreeIndentString = xmlStrdup((xmlChar *)StringValuePtr(string));
  return (string);
}

.default_validity_checkingObject

Determine whether parsers perform XML validation by default.



622
623
624
625
626
627
628
# File 'ext/libxml/ruby_xml.c', line 622

static VALUE rxml_default_validity_checking_get(VALUE klass)
{
  if (xmlDoValidityCheckingDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_validity_checking=(true) ⇒ Object

Controls whether parsers perform XML validation by default.



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'ext/libxml/ruby_xml.c', line 636

static VALUE rxml_default_validity_checking_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_FALSE)
  {
    xmlDoValidityCheckingDefaultValue = 0;
    return (Qfalse);
  }
  else
  {
    xmlDoValidityCheckingDefaultValue = 1;
    return (Qtrue);
  }
}

.default_warningsObject

Determine whether parsers output warnings by default.



656
657
658
659
660
661
662
# File 'ext/libxml/ruby_xml.c', line 656

static VALUE rxml_default_warnings_get(VALUE klass)
{
  if (xmlGetWarningsDefaultValue)
    return (Qtrue);
  else
    return (Qfalse);
}

.default_warnings=(true) ⇒ Object

Controls whether parsers output warnings by default.



670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'ext/libxml/ruby_xml.c', line 670

static VALUE rxml_default_warnings_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_FALSE)
  {
    xmlGetWarningsDefaultValue = 0;
    return (Qfalse);
  }
  else
  {
    xmlGetWarningsDefaultValue = 1;
    return (Qtrue);
  }
}

.enabled_automata?Boolean

Determine whether libxml regexp automata support is enabled.

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'ext/libxml/ruby_xml.c', line 50

static VALUE rxml_enabled_automata_q(VALUE klass)
{
#ifdef LIBXML_AUTOMATA_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_c14n?Boolean

Determine whether libxml ‘canonical XML’ support is enabled. See “Canonical XML” (www.w3.org/TR/xml-c14n)

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
# File 'ext/libxml/ruby_xml.c', line 66

static VALUE rxml_enabled_c14n_q(VALUE klass)
{
#ifdef LIBXML_C14N_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_catalog?Boolean

Determine whether libxml resource catalog support is enabled.

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
# File 'ext/libxml/ruby_xml.c', line 81

static VALUE rxml_enabled_catalog_q(VALUE klass)
{
#ifdef LIBXML_CATALOG_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_debug?Boolean

Determine whether libxml debugging support is enabled.

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
# File 'ext/libxml/ruby_xml.c', line 96

static VALUE rxml_enabled_debug_q(VALUE klass)
{
#ifdef LIBXML_DEBUG_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_docbook?Boolean

Determine whether libxml docbook support is enabled.

Returns:

  • (Boolean)


111
112
113
114
115
116
117
118
# File 'ext/libxml/ruby_xml.c', line 111

static VALUE rxml_enabled_docbook_q(VALUE klass)
{
#ifdef LIBXML_DOCB_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_ftp?Boolean

Determine whether libxml ftp client support is enabled.

Returns:

  • (Boolean)


126
127
128
129
130
131
132
133
# File 'ext/libxml/ruby_xml.c', line 126

static VALUE rxml_enabled_ftp_q(VALUE klass)
{
#ifdef LIBXML_FTP_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_html?Boolean

Determine whether libxml html support is enabled.

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
# File 'ext/libxml/ruby_xml.c', line 156

static VALUE rxml_enabled_html_q(VALUE klass)
{
#ifdef LIBXML_HTML_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_http?Boolean

Determine whether libxml http client support is enabled.

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
# File 'ext/libxml/ruby_xml.c', line 141

static VALUE rxml_enabled_http_q(VALUE klass)
{
#ifdef LIBXML_HTTP_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_iconv?Boolean

Determine whether libxml iconv support is enabled.

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
# File 'ext/libxml/ruby_xml.c', line 171

static VALUE rxml_enabled_iconv_q(VALUE klass)
{
#ifdef LIBXML_ICONV_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_memory_debug?Boolean

Determine whether libxml memory location debugging support is enabled.

Returns:

  • (Boolean)


187
188
189
190
191
192
193
194
# File 'ext/libxml/ruby_xml.c', line 187

static VALUE rxml_enabled_memory_debug_location_q(VALUE klass)
{
#ifdef DEBUG_MEMORY_LOCATION
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_regexp?Boolean

Determine whether libxml regular expression support is enabled.

Returns:

  • (Boolean)


202
203
204
205
206
207
208
209
# File 'ext/libxml/ruby_xml.c', line 202

static VALUE rxml_enabled_regexp_q(VALUE klass)
{
#ifdef LIBXML_REGEXP_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_schemas?Boolean

Determine whether libxml schema support is enabled.

Returns:

  • (Boolean)


217
218
219
220
221
222
223
224
# File 'ext/libxml/ruby_xml.c', line 217

static VALUE rxml_enabled_schemas_q(VALUE klass)
{
#ifdef LIBXML_SCHEMAS_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_thread?Boolean

Determine whether thread-safe semantics support for libxml is enabled and is used by this ruby extension. Threading support in libxml uses pthread on Unix-like systems and Win32 threads on Windows.

Returns:

  • (Boolean)


234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/libxml/ruby_xml.c', line 234

static VALUE rxml_enabled_thread_q(VALUE klass)
{
  /* This won't be defined unless this code is compiled with _REENTRANT or __MT__
   * defined or the compiler is in C99 mode.
   *
   * Note the relevant portion libxml/xmlversion.h on a thread-enabled build:
   *
   *    #if defined(_REENTRANT) || defined(__MT__) || \
   *        (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L))
   *        #define LIBXML_THREAD_ENABLED
   *    #endif
   *
   */
#ifdef LIBXML_THREAD_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_unicode?Boolean

Determine whether libxml unicode support is enabled.

Returns:

  • (Boolean)


260
261
262
263
264
265
266
267
# File 'ext/libxml/ruby_xml.c', line 260

static VALUE rxml_enabled_unicode_q(VALUE klass)
{
#ifdef LIBXML_UNICODE_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_xinclude?Boolean

Determine whether libxml xinclude support is enabled.

Returns:

  • (Boolean)


275
276
277
278
279
280
281
282
# File 'ext/libxml/ruby_xml.c', line 275

static VALUE rxml_enabled_xinclude_q(VALUE klass)
{
#ifdef LIBXML_XINCLUDE_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_xpath?Boolean

Determine whether libxml xpath support is enabled.

Returns:

  • (Boolean)


290
291
292
293
294
295
296
297
# File 'ext/libxml/ruby_xml.c', line 290

static VALUE rxml_enabled_xpath_q(VALUE klass)
{
#ifdef LIBXML_XPATH_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_xpointer?Boolean

Determine whether libxml xpointer support is enabled.

Returns:

  • (Boolean)


305
306
307
308
309
310
311
312
# File 'ext/libxml/ruby_xml.c', line 305

static VALUE rxml_enabled_xpointer_q(VALUE klass)
{
#ifdef LIBXML_XPTR_ENABLED
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.enabled_zlib?Boolean

Determine whether libxml zlib support is enabled.

Returns:

  • (Boolean)


320
321
322
323
324
325
326
327
# File 'ext/libxml/ruby_xml.c', line 320

static VALUE rxml_enabled_zlib_q(VALUE klass)
{
#ifdef HAVE_ZLIB_H
  return(Qtrue);
#else
  return (Qfalse);
#endif
}

.featuresArray

Obtains an array of strings representing features supported (and enabled) by the installed libxml.

Returns:

  • (Array)


727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
# File 'ext/libxml/ruby_xml.c', line 727

static VALUE rxml_features(VALUE klass)
{
  VALUE arr, str;
  int i, len = MAX_LIBXML_FEATURES_LEN;
  char **list = NULL;

  list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
  MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);

  arr = rb_ary_new();
  if (xmlGetFeaturesList(&len, (const char **) list) == -1)
    return Qnil;

  for (i = 0; i < len; i++)
  {
    str = rb_str_new2((const char *) list[i]);
    rb_gc_unregister_address(&str);
    rb_ary_push(arr, str);
  }

  if (len == MAX_LIBXML_FEATURES_LEN)
    rb_warn(
        "Please contact [email protected] and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");

  ruby_xfree(list);
  return (arr);
}

.indent_tree_outputObject

Determines whether XML output will be indented (using the string supplied to default_indent_tree_string)



762
763
764
765
766
767
768
# File 'ext/libxml/ruby_xml.c', line 762

static VALUE rxml_indent_tree_output_get(VALUE klass)
{
  if (xmlIndentTreeOutput)
    return (Qtrue);
  else
    return (Qfalse);
}

.indent_tree_output=(true) ⇒ Object

Controls whether XML output will be indented (using the string supplied to default_indent_tree_string)



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'ext/libxml/ruby_xml.c', line 777

static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE bool)
{
  if (TYPE(bool) == T_TRUE)
  {
    xmlIndentTreeOutput = 1;
    return (Qtrue);
  }
  else if (TYPE(bool) == T_FALSE)
  {
    xmlIndentTreeOutput = 0;
    return (Qfalse);
  }
  else
  {
    rb_raise(rb_eArgError, "Invalid argument, must be boolean");
  }
}

.memory_dumpObject

Perform a parser memory dump (requires memory debugging support in libxml).



802
803
804
805
806
807
808
809
810
811
# File 'ext/libxml/ruby_xml.c', line 802

static VALUE rxml_memory_dump(VALUE self)
{
#ifdef DEBUG_MEMORY_LOCATION
  xmlMemoryDump();
  return(Qtrue);
#else
  rb_warn("libxml was compiled without memory debugging support");
  return (Qfalse);
#endif
}

.memory_usedObject

Perform a parser memory dump (requires memory debugging support in libxml).



820
821
822
823
824
825
826
827
828
# File 'ext/libxml/ruby_xml.c', line 820

static VALUE rxml_memory_used(VALUE self)
{
#ifdef DEBUG_MEMORY_LOCATION
  return(INT2NUM(xmlMemUsed()));
#else
  rb_warn("libxml was compiled without memory debugging support");
  return (Qfalse);
#endif
}