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/schema.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/schema/type.rb,
lib/libxml/xpath_object.rb,
lib/libxml/sax_callbacks.rb,
lib/libxml/schema/element.rb,
lib/libxml/schema/attribute.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, Writer, 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)


93
94
95
96
97
# File 'ext/libxml/ruby_xml.c', line 93

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

.catalog_remove(catalog) ⇒ true

Remove the specified resource catalog.

Returns:

  • (true)


105
106
107
108
109
110
# File 'ext/libxml/ruby_xml.c', line 105

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)


119
120
121
122
123
# File 'ext/libxml/ruby_xml.c', line 119

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)



417
418
419
420
421
422
423
424
425
426
427
428
# File 'ext/libxml/ruby_xml.c', line 417

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)



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'ext/libxml/ruby_xml.c', line 437

static VALUE rxml_debug_entities_set(VALUE klass, VALUE value)
{
#ifdef LIBXML_DEBUG_ENABLED
  if (value == Qfalse)
  {
    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).



772
773
774
775
776
777
778
779
780
# File 'ext/libxml/ruby_xml.c', line 772

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).



789
790
791
792
793
794
795
796
797
798
799
# File 'ext/libxml/ruby_xml.c', line 789

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.



461
462
463
464
465
466
467
# File 'ext/libxml/ruby_xml.c', line 461

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.



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'ext/libxml/ruby_xml.c', line 475

static VALUE rxml_default_keep_blanks_set(VALUE klass, VALUE value)
{
  if (value == Qfalse)
  {
    xmlKeepBlanksDefaultValue = 0;
    return (Qfalse);
  }
  else if (value == Qtrue)
  {
    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.



533
534
535
536
537
538
539
# File 'ext/libxml/ruby_xml.c', line 533

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.



547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'ext/libxml/ruby_xml.c', line 547

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

.default_load_external_dtdObject

Determine whether parsers load external DTDs by default.



499
500
501
502
503
504
505
# File 'ext/libxml/ruby_xml.c', line 499

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.



513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'ext/libxml/ruby_xml.c', line 513

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

.default_optionsInteger

Returns an integer that summarize libxml2’s default options.

Returns:

  • (Integer)


592
593
594
595
596
# File 'ext/libxml/ruby_xml.c', line 592

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.



604
605
606
607
608
609
610
# File 'ext/libxml/ruby_xml.c', line 604

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.



618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'ext/libxml/ruby_xml.c', line 618

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

.default_substitute_entitiesObject

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



639
640
641
642
643
644
645
# File 'ext/libxml/ruby_xml.c', line 639

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.



654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'ext/libxml/ruby_xml.c', line 654

static VALUE rxml_default_substitute_entities_set(VALUE klass, VALUE value)
{
  if (value == 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.



675
676
677
678
679
680
681
# File 'ext/libxml/ruby_xml.c', line 675

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.



690
691
692
693
694
695
# File 'ext/libxml/ruby_xml.c', line 690

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

.default_validity_checkingObject

Determine whether parsers perform XML validation by default.



703
704
705
706
707
708
709
# File 'ext/libxml/ruby_xml.c', line 703

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.



717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'ext/libxml/ruby_xml.c', line 717

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

.default_warningsObject

Determine whether parsers output warnings by default.



737
738
739
740
741
742
743
# File 'ext/libxml/ruby_xml.c', line 737

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.



751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'ext/libxml/ruby_xml.c', line 751

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

.enabled_automata?Boolean

Determine whether libxml regexp automata support is enabled.

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
# File 'ext/libxml/ruby_xml.c', line 131

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)


147
148
149
150
151
152
153
154
# File 'ext/libxml/ruby_xml.c', line 147

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)


162
163
164
165
166
167
168
169
# File 'ext/libxml/ruby_xml.c', line 162

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)


177
178
179
180
181
182
183
184
# File 'ext/libxml/ruby_xml.c', line 177

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)


192
193
194
195
196
197
198
199
# File 'ext/libxml/ruby_xml.c', line 192

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)


207
208
209
210
211
212
213
214
# File 'ext/libxml/ruby_xml.c', line 207

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)


237
238
239
240
241
242
243
244
# File 'ext/libxml/ruby_xml.c', line 237

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)


222
223
224
225
226
227
228
229
# File 'ext/libxml/ruby_xml.c', line 222

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)


252
253
254
255
256
257
258
259
# File 'ext/libxml/ruby_xml.c', line 252

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)


268
269
270
271
272
273
274
275
# File 'ext/libxml/ruby_xml.c', line 268

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)


283
284
285
286
287
288
289
290
# File 'ext/libxml/ruby_xml.c', line 283

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)


298
299
300
301
302
303
304
305
# File 'ext/libxml/ruby_xml.c', line 298

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)


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'ext/libxml/ruby_xml.c', line 315

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)


341
342
343
344
345
346
347
348
# File 'ext/libxml/ruby_xml.c', line 341

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)


356
357
358
359
360
361
362
363
# File 'ext/libxml/ruby_xml.c', line 356

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)


371
372
373
374
375
376
377
378
# File 'ext/libxml/ruby_xml.c', line 371

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)


386
387
388
389
390
391
392
393
# File 'ext/libxml/ruby_xml.c', line 386

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)


401
402
403
404
405
406
407
408
# File 'ext/libxml/ruby_xml.c', line 401

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)


808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'ext/libxml/ruby_xml.c', line 808

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)



843
844
845
846
847
848
849
# File 'ext/libxml/ruby_xml.c', line 843

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)



858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'ext/libxml/ruby_xml.c', line 858

static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value)
{
  if (value == Qtrue)
  {
    xmlIndentTreeOutput = 1;
    return (Qtrue);
  }
  else if (value == Qfalse)
  {
    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).



883
884
885
886
887
888
889
890
891
892
# File 'ext/libxml/ruby_xml.c', line 883

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).



901
902
903
904
905
906
907
908
909
# File 'ext/libxml/ruby_xml.c', line 901

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
}