class Nokogiri::XML::ElementContent - nokogiri-1.18.10 Documentation

# class Nokogiri::XML::ElementContent

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.

### Constants

ELEMENT
MULT
ONCE

  Possible content occurrences

OPT
OR
PCDATA

  Possible definitions of type

PLUS
SEQ

### Attributes

document[R]

### Public Instance Methods

children() click to toggle source

Get the children of this `ElementContent` node

    # File lib/nokogiri/xml/element_content.rb, line 35
    def children
      [c1, c2].compact
    end

name → String click to toggle source

Returns

  The content element’s `name`

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

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

occur → Integer click to toggle source

Returns

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

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

      return INT2NUM(elem->ocur);
    }

prefix → String click to toggle source

Returns

  The content element’s namespace `prefix`.

    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 click to toggle source

Returns

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

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

      return INT2NUM(elem->type);
    }

### Private Instance Methods

c1() click to toggle source

Get the first child.

    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() click to toggle source

Get the second child.

    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);
    }

inspect_attributes() click to toggle source

    # File lib/nokogiri/xml/element_content.rb, line 41
    def inspect_attributes
      [:prefix, :name, :type, :occur, :children]
    end