Class: LibXML::XML::Parser::Context

Inherits:
Object
  • Object
show all
Defined in:
ext/libxml/ruby_xml_parser_context.c,
ext/libxml/ruby_xml_parser_context.c

Overview

The XML::Parser::Context class provides in-depth control over how a document is parsed.

Direct Known Subclasses

HTMLParser::Context

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.XML::Parser::Context.document(document) ⇒ XML::Parser::Context

Creates a new parser context based on the specified document.

Parameters:

document - An XML::Document instance
options - A or'ed together list of LibXML::XML::Parser::Options values


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/libxml/ruby_xml_parser_context.c', line 52

static VALUE rxml_parser_context_document(int argc, VALUE* argv, VALUE klass)
{
  VALUE document, options;
  rb_scan_args(argc, argv, "11", &document, &options);

  if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
    rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");

  xmlDocPtr xdoc;
  xmlChar *buffer;
  int length;
  TypedData_Get_Struct(document, xmlDoc, &rxml_document_data_type, xdoc);
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0);

  xmlParserCtxtPtr ctxt = xmlCreateDocParserCtxt(buffer);

  if (!ctxt)
    rxml_raise(xmlGetLastError());

  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and 
     xmlCtxtUseOptionsInternal (called below) initialize slightly different
     context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
     sets to 0 and xmlCtxtUseOptionsInternal sets to 1.  So we have to call both. */
  xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));

  return rxml_parser_context_wrap(ctxt);
}

.XML::Parser::Context.file(file) ⇒ XML::Parser::Context

Creates a new parser context based on the specified file or uri.

Parameters:

file - A filename or uri
options - A or'ed together list of LibXML::XML::Parser::Options values


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/libxml/ruby_xml_parser_context.c', line 90

static VALUE rxml_parser_context_file(int argc, VALUE* argv, VALUE klass)
{
  VALUE file, options;
  rb_scan_args(argc, argv, "11", &file, &options);

  xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0);

  if (!ctxt)
    rxml_raise(xmlGetLastError());

  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and 
     xmlCtxtUseOptionsInternal (called below) initialize slightly different
     context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
     sets to 0 and xmlCtxtUseOptionsInternal sets to 1.  So we have to call both. */
  xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));

  return rxml_parser_context_wrap(ctxt);
}

.XML::Parser::Context.io(io) ⇒ XML::Parser::Context

Creates a new parser context based on the specified io object.

Parameters:

io - A ruby IO object
options - A or'ed together list of LibXML::XML::Parser::Options values


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/libxml/ruby_xml_parser_context.c', line 153

static VALUE rxml_parser_context_io(int argc, VALUE* argv, VALUE klass)
{
  VALUE io, options;
  rb_scan_args(argc, argv, "11", &io, &options);

  if (NIL_P(io))
    rb_raise(rb_eTypeError, "Must pass in an IO object");

  xmlParserInputBufferPtr input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
                                       (void*)io, XML_CHAR_ENCODING_NONE);

  xmlParserCtxtPtr ctxt = xmlNewParserCtxt();

  if (!ctxt)
  {
    xmlFreeParserInputBuffer(input);
    rxml_raise(xmlGetLastError());
  }

  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and 
     xmlCtxtUseOptionsInternal (called below) initialize slightly different
     context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
     sets to 0 and xmlCtxtUseOptionsInternal sets to 1.  So we have to call both. */
  xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));

  xmlParserInputPtr stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);

  if (!stream)
  {
    xmlFreeParserInputBuffer(input);
    xmlFreeParserCtxt(ctxt);
    rxml_raise(xmlGetLastError());
  }
  inputPush(ctxt, stream);
  VALUE result = rxml_parser_context_wrap(ctxt);

  /* Attach io object to parser so it won't get freed.*/
  rb_ivar_set(result, IO_ATTR, io);

  return result;
}

.XML::Parser::Context.string(string) ⇒ XML::Parser::Context

Creates a new parser context based on the specified string.

Parameters:

string - A string that contains the data to parse
options - A or'ed together list of LibXML::XML::Parser::Options values


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'ext/libxml/ruby_xml_parser_context.c', line 119

static VALUE rxml_parser_context_string(int argc, VALUE* argv, VALUE klass)
{
  VALUE string, options;
  rb_scan_args(argc, argv, "11", &string, &options);

  Check_Type(string, T_STRING);

  if (RSTRING_LEN(string) == 0)
    rb_raise(rb_eArgError, "Must specify a string with one or more characters");

  xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string), (int)RSTRING_LEN(string));
  
  if (!ctxt)
    rxml_raise(xmlGetLastError());

  /* This is annoying, but xmlInitParserCtxt (called indirectly above) and 
     xmlCtxtUseOptionsInternal (called below) initialize slightly different
     context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
     sets to 0 and xmlCtxtUseOptionsInternal sets to 1.  So we have to call both. */
  xmlCtxtUseOptions(ctxt, options == Qnil ? 0 : NUM2INT(options));

  return rxml_parser_context_wrap(ctxt);
}

Instance Method Details

#base_uriObject

Obtain the base url for this parser context.



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

static VALUE rxml_parser_context_base_uri_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->input && ctxt->input->filename)
    return rxml_new_cstr((const xmlChar*)ctxt->input->filename, ctxt->encoding);
  else
    return Qnil;
}

#base_uri=(url) ⇒ Object

Sets the base url for this parser context.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'ext/libxml/ruby_xml_parser_context.c', line 218

static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  Check_Type(url, T_STRING);

  if (ctxt->input && !ctxt->input->filename)
  {
    const char* xurl = StringValuePtr(url);
    ctxt->input->filename = (const char*)xmlStrdup((const xmlChar*)xurl);
  }
  return self;
}

#closenil

Closes the underlying input streams. This is useful when parsing a large amount of files and you want to close the files without relying on Ruby’s garbage collector to run.

Returns:

  • (nil)


241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/libxml/ruby_xml_parser_context.c', line 241

static VALUE rxml_parser_context_close(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  xmlParserInputPtr xinput;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  while ((xinput = inputPop(ctxt)) != NULL)
  {
	 xmlFreeInputStream(xinput);
  }
  return Qnil;
}

#data_directoryObject

Obtain the data directory associated with this context.



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

static VALUE rxml_parser_context_data_directory_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->directory == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr((const xmlChar*)ctxt->directory, ctxt->encoding));
}

#depthNumeric

Obtain the depth of this context.

Returns:

  • (Numeric)


277
278
279
280
281
282
283
# File 'ext/libxml/ruby_xml_parser_context.c', line 277

static VALUE rxml_parser_context_depth_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->depth));
}

#disable_cdata=(value) ⇒ Object

Control whether CDATA nodes will be created in this context.



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'ext/libxml/ruby_xml_parser_context.c', line 309

static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->sax == NULL)
    rb_raise(rb_eRuntimeError, "Sax handler is not yet set");

  /* LibXML controls this internally with the default SAX handler. */ 
  if (value)
    ctxt->sax->cdataBlock = NULL;
  else
    ctxt->sax->cdataBlock = xmlSAX2CDataBlock;

  return value;
}

#disable_cdata?Boolean

Determine whether CDATA nodes will be created in this context.

Returns:

  • (Boolean)


291
292
293
294
295
296
297
298
299
300
301
# File 'ext/libxml/ruby_xml_parser_context.c', line 291

static VALUE rxml_parser_context_disable_cdata_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  /* LibXML controls this internally with the default SAX handler. */
  if (ctxt->sax && ctxt->sax->cdataBlock)
    return (Qfalse);
  else
    return (Qtrue);
}

#disable_sax?Boolean

Determine whether SAX-based processing is disabled in this context.

Returns:

  • (Boolean)


333
334
335
336
337
338
339
340
341
342
# File 'ext/libxml/ruby_xml_parser_context.c', line 333

static VALUE rxml_parser_context_disable_sax_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->disableSAX)
    return (Qtrue);
  else
    return (Qfalse);
}

#docbook?Boolean

Determine whether this is a docbook context.

Returns:

  • (Boolean)


350
351
352
353
354
355
356
357
358
359
# File 'ext/libxml/ruby_xml_parser_context.c', line 350

static VALUE rxml_parser_context_docbook_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->html == 2) // TODO check this
    return (Qtrue);
  else
    return (Qfalse);
}

#encodingXML::Encoding::UTF_8

Obtain the character encoding identifier used in this context.



368
369
370
371
372
373
# File 'ext/libxml/ruby_xml_parser_context.c', line 368

static VALUE rxml_parser_context_encoding_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
  return INT2NUM(xmlParseCharEncoding((const char*)ctxt->encoding));
}

#encoding=(XML) ⇒ Object

Sets the character encoding for this context.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'ext/libxml/ruby_xml_parser_context.c', line 381

static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
{
  xmlParserCtxtPtr ctxt;
  int result;
  const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding));
  xmlCharEncodingHandlerPtr hdlr = xmlFindCharEncodingHandler(xencoding);
  
  if (!hdlr)
    rb_raise(rb_eArgError, "Unknown encoding: %i", NUM2INT(encoding));

  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
  result = xmlSwitchToEncoding(ctxt, hdlr);

  if (result != 0)
    rxml_raise(xmlGetLastError());

  if (ctxt->encoding != NULL)
    xmlFree((xmlChar *) ctxt->encoding);

  ctxt->encoding = xmlStrdup((const xmlChar *) xencoding);
  return self;
}

#errnoNumeric

Obtain the last-error number in this context.

Returns:

  • (Numeric)


410
411
412
413
414
415
416
# File 'ext/libxml/ruby_xml_parser_context.c', line 410

static VALUE rxml_parser_context_errno_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->errNo));
}

#html?Boolean

Determine whether this is an html context.

Returns:

  • (Boolean)


424
425
426
427
428
429
430
431
432
433
# File 'ext/libxml/ruby_xml_parser_context.c', line 424

static VALUE rxml_parser_context_html_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->html == 1)
    return (Qtrue);
  else
    return (Qfalse);
}

#max_num_streamsNumeric

Obtain the limit on the number of IO streams opened in this context.

Returns:

  • (Numeric)


442
443
444
445
446
447
448
449
# File 'ext/libxml/ruby_xml_parser_context.c', line 442

static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
{
  // TODO alias to max_streams and dep this?
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->inputMax));
}

#num_streamsObject

Obtain the actual number of IO streams in this context.



458
459
460
461
462
463
464
# File 'ext/libxml/ruby_xml_parser_context.c', line 458

static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->inputNr));
}

#keep_blanks?Boolean

Determine whether parsers in this context retain whitespace.

Returns:

  • (Boolean)


473
474
475
476
477
478
479
480
481
482
# File 'ext/libxml/ruby_xml_parser_context.c', line 473

static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->keepBlanks)
    return (Qtrue);
  else
    return (Qfalse);
}

#name_depthNumeric

Obtain the name depth for this context.

Returns:

  • (Numeric)


490
491
492
493
494
495
496
# File 'ext/libxml/ruby_xml_parser_context.c', line 490

static VALUE rxml_parser_context_name_depth_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->nameNr));
}

#name_depth_maxNumeric

Obtain the maximum name depth for this context.

Returns:

  • (Numeric)


504
505
506
507
508
509
510
# File 'ext/libxml/ruby_xml_parser_context.c', line 504

static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->nameMax));
}

#name_nodeObject

Obtain the name node for this context.



518
519
520
521
522
523
524
525
526
527
# File 'ext/libxml/ruby_xml_parser_context.c', line 518

static VALUE rxml_parser_context_name_node_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->name == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr( ctxt->name, ctxt->encoding));
}

#name_tabArray

Obtain the name table for this context.

Returns:

  • (Array)


535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'ext/libxml/ruby_xml_parser_context.c', line 535

static VALUE rxml_parser_context_name_tab_get(VALUE self)
{
  int i;
  xmlParserCtxtPtr ctxt;
  VALUE tab_ary;

  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->nameTab == NULL)
    return (Qnil);

  tab_ary = rb_ary_new();

  for (i = (ctxt->nameNr - 1); i >= 0; i--)
  {
    if (ctxt->nameTab[i] == NULL)
      continue;
    else
      rb_ary_push(tab_ary, rxml_new_cstr( ctxt->nameTab[i], ctxt->encoding));
  }

  return (tab_ary);
}

#nodeObject

Obtain the root node of this context.



579
580
581
582
583
584
585
586
587
588
# File 'ext/libxml/ruby_xml_parser_context.c', line 579

static VALUE rxml_parser_context_node_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->node == NULL)
    return (Qnil);
  else
    return (rxml_node_wrap(ctxt->node));
}

#node_depthNumeric

Obtain the node depth for this context.

Returns:

  • (Numeric)


565
566
567
568
569
570
571
# File 'ext/libxml/ruby_xml_parser_context.c', line 565

static VALUE rxml_parser_context_node_depth_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->nodeNr));
}

#node_depth_maxNumeric

Obtain the maximum node depth for this context.

Returns:

  • (Numeric)


596
597
598
599
600
601
602
# File 'ext/libxml/ruby_xml_parser_context.c', line 596

static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->nodeMax));
}

#num_charsNumeric

Obtain the number of characters in this context.

Returns:

  • (Numeric)


610
611
612
613
614
615
616
# File 'ext/libxml/ruby_xml_parser_context.c', line 610

static VALUE rxml_parser_context_num_chars_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (LONG2NUM(ctxt->nbChars));
}

#>(XML: :Parser::Options::NOENT) ⇒ Object

Returns the parser options for this context. Multiple options can be combined by using Bitwise OR (|).



626
627
628
629
630
631
632
# File 'ext/libxml/ruby_xml_parser_context.c', line 626

static VALUE rxml_parser_context_options_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return INT2NUM(ctxt->options);
}

#options=(XML) ⇒ Object #XML::Parser::Options::NOCDATAObject

Provides control over the execution of a parser. Valid values are the constants defined on XML::Parser::Options. Multiple options can be combined by using Bitwise OR (|).



643
644
645
646
647
648
649
650
651
652
# File 'ext/libxml/ruby_xml_parser_context.c', line 643

static VALUE rxml_parser_context_options_set(VALUE self, VALUE options)
{
  xmlParserCtxtPtr ctxt;
  Check_Type(options, T_FIXNUM);

  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
  xmlCtxtUseOptions(ctxt, NUM2INT(options));

  return self;
}

#recovery=(true) ⇒ Object

Control whether recovery mode is enabled in this context.



679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'ext/libxml/ruby_xml_parser_context.c', line 679

static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE value)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (value == Qfalse)
  {
    ctxt->recovery = 0;
    return (Qfalse);
  }
  else
  {
    ctxt->recovery = 1;
    return (Qtrue);
  }
}

#recovery?Boolean

Determine whether recovery mode is enabled in this context.

Returns:

  • (Boolean)


661
662
663
664
665
666
667
668
669
670
# File 'ext/libxml/ruby_xml_parser_context.c', line 661

static VALUE rxml_parser_context_recovery_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->recovery)
    return (Qtrue);
  else
    return (Qfalse);
}

#replace_entities=(true) ⇒ Object

Control whether external entity replacement is enabled in this context.



721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
# File 'ext/libxml/ruby_xml_parser_context.c', line 721

static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE value)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (value == Qfalse)
  {
    ctxt->replaceEntities = 0;
    return (Qfalse);
  }
  else
  {
    ctxt->replaceEntities = 1;
    return (Qtrue);
  }
}

#replace_entities?Boolean

Determine whether external entity replacement is enabled in this context.

Returns:

  • (Boolean)


703
704
705
706
707
708
709
710
711
712
# File 'ext/libxml/ruby_xml_parser_context.c', line 703

static VALUE rxml_parser_context_replace_entities_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->replaceEntities)
    return (Qtrue);
  else
    return (Qfalse);
}

#space_depthNumeric

Obtain the space depth for this context.

Returns:

  • (Numeric)


744
745
746
747
748
749
750
# File 'ext/libxml/ruby_xml_parser_context.c', line 744

static VALUE rxml_parser_context_space_depth_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->spaceNr));
}

#space_depthNumeric

Obtain the maximum space depth for this context.

Returns:

  • (Numeric)


758
759
760
761
762
763
764
# File 'ext/libxml/ruby_xml_parser_context.c', line 758

static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  return (INT2NUM(ctxt->spaceMax));
}

#standalone?Boolean

Determine whether this is a standalone context.

Returns:

  • (Boolean)


865
866
867
868
869
870
871
872
873
874
# File 'ext/libxml/ruby_xml_parser_context.c', line 865

static VALUE rxml_parser_context_standalone_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->standalone)
    return (Qtrue);
  else
    return (Qfalse);
}

#stats?Boolean

Determine whether this context maintains statistics.

Returns:

  • (Boolean)


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

static VALUE rxml_parser_context_stats_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->record_info)
    return (Qtrue);
  else
    return (Qfalse);
}

#subset_external?Boolean

Determine whether this context is a subset of an external context.

Returns:

  • (Boolean)


773
774
775
776
777
778
779
780
781
782
# File 'ext/libxml/ruby_xml_parser_context.c', line 773

static VALUE rxml_parser_context_subset_external_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->inSubset == 2)
    return (Qtrue);
  else
    return (Qfalse);
}

#subset_external_system_idObject

Obtain this context’s external subset system identifier. (valid only if either of subset_external? or subset_internal? is true).



848
849
850
851
852
853
854
855
856
857
# File 'ext/libxml/ruby_xml_parser_context.c', line 848

static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->extSubSystem == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr( ctxt->extSubSystem, ctxt->encoding));
}

#subset_external_uriObject

Obtain this context’s external subset URI. (valid only if either of subset_external? or subset_internal? is true).



829
830
831
832
833
834
835
836
837
838
# File 'ext/libxml/ruby_xml_parser_context.c', line 829

static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->extSubURI == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr( ctxt->extSubURI, ctxt->encoding));
}

#subset_internal?Boolean

Determine whether this context is a subset of an internal context.

Returns:

  • (Boolean)


791
792
793
794
795
796
797
798
799
800
# File 'ext/libxml/ruby_xml_parser_context.c', line 791

static VALUE rxml_parser_context_subset_internal_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->inSubset == 1)
    return (Qtrue);
  else
    return (Qfalse);
}

#subset_internal_nameObject

Obtain this context’s subset name (valid only if either of subset_external? or subset_internal? is true).



810
811
812
813
814
815
816
817
818
819
# File 'ext/libxml/ruby_xml_parser_context.c', line 810

static VALUE rxml_parser_context_subset_name_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->intSubName == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr(ctxt->intSubName, ctxt->encoding));
}

#valid?Object

Determine whether this context is valid.



899
900
901
902
903
904
905
906
907
908
# File 'ext/libxml/ruby_xml_parser_context.c', line 899

static VALUE rxml_parser_context_valid_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->valid)
    return (Qtrue);
  else
    return (Qfalse);
}

#validate?Boolean

Determine whether validation is enabled in this context.

Returns:

  • (Boolean)


916
917
918
919
920
921
922
923
924
925
# File 'ext/libxml/ruby_xml_parser_context.c', line 916

static VALUE rxml_parser_context_validate_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->validate)
    return (Qtrue);
  else
    return (Qfalse);
}

#versionObject

Obtain this context’s version identifier.



933
934
935
936
937
938
939
940
941
942
# File 'ext/libxml/ruby_xml_parser_context.c', line 933

static VALUE rxml_parser_context_version_get(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->version == NULL)
    return (Qnil);
  else
    return (rxml_new_cstr( ctxt->version, ctxt->encoding));
}

#well_formed?Boolean

Determine whether this context contains well-formed XML.

Returns:

  • (Boolean)


950
951
952
953
954
955
956
957
958
959
# File 'ext/libxml/ruby_xml_parser_context.c', line 950

static VALUE rxml_parser_context_well_formed_q(VALUE self)
{
  xmlParserCtxtPtr ctxt;
  TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);

  if (ctxt->wellFormed)
    return (Qtrue);
  else
    return (Qfalse);
}