123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::XML::ElementContent

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, PP::Node
Inherits: Object
Defined in: lib/nokogiri/xml/element_content.rb,
ext/nokogiri/xml_element_content.c,
ext/nokogiri/xml_node.c

Overview

Represents the allowed content in an Element Declaration inside a DTD:

<?xml version="1.0"?><?TEST-STYLE PIDATA?>
<!DOCTYPE staff SYSTEM "staff.dtd" [
   <!ELEMENT div1 (head, (p | list | note)*, div2*)>
]>
</root>

ElementContent represents the binary tree inside the <!ELEMENT> tag shown above that lists the possible content for the div1 tag.

Constant Summary

PP::Node - Included

COLLECTIONS

Instance Attribute Summary

Instance Method Summary

PP::Node - Included

Instance Attribute Details

#document (readonly)

[ GitHub ]

  
# File 'lib/nokogiri/xml/element_content.rb', line 31

attr_reader :document

#name (readonly)

Alias for Node#node_name.

Instance Method Details

#c1 (private)

Get the first child.

[ GitHub ]

  
# File 'ext/nokogiri/xml_element_content.c', line 44

static VALUE
get_c1(VALUE self)
{
  xmlElementContentPtr elem;
  TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);

  if (!elem->c1) { return Qnil; }
  return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c1);
}

#c2 (private)

Get the second child.

[ GitHub ]

  
# File 'ext/nokogiri/xml_element_content.c', line 57

static VALUE
get_c2(VALUE self)
{
  xmlElementContentPtr elem;
  TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);

  if (!elem->c2) { return Qnil; }
  return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c2);
}

#children

Get the children of this ElementContent node

[ GitHub ]

  
# File 'lib/nokogiri/xml/element_content.rb', line 35

def children
  [c1, c2].compact
end

#inspect_attributes (private)

[ GitHub ]

  
# File 'lib/nokogiri/xml/element_content.rb', line 41

def inspect_attributes
  [:prefix, :name, :type, :occur, :children]
end

#occur(→ Integer)

Returns

The content element’s occur flag. Possible values are ONCE, OPT, MULT or PLUS.

[ GitHub ]

  
# File 'ext/nokogiri/xml_element_content.c', line 73

static VALUE
get_occur(VALUE self)
{
  xmlElementContentPtr elem;
  TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);

  return INT2NUM(elem->ocur);
}

#prefix(→ String)

Returns

The content element’s namespace prefix.

[ GitHub ]

  
# File 'ext/nokogiri/xml_element_content.c', line 88

static VALUE
get_prefix(VALUE self)
{
  xmlElementContentPtr elem;
  TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);

  if (!elem->prefix) { return Qnil; }

  return NOKOGIRI_STR_NEW2(elem->prefix);
}

#type(→ Integer)

Returns

The content element’s type. Possible values are PCDATA, ELEMENT, SEQ, or OR.

[ GitHub ]

  
# File 'ext/nokogiri/xml_element_content.c', line 32

static VALUE
get_type(VALUE self)
{
  xmlElementContentPtr elem;
  TypedData_Get_Struct(self, xmlElementContent, &xml_element_content_type, elem);

  return INT2NUM(elem->type);
}