123456789_123456789_123456789_123456789_123456789_

Class: REXML::AttlistDecl

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Child
Instance Chain:
self, Enumerable, Child, Node
Inherits: REXML::Child
Defined in: lib/rexml/attlistdecl.rb

Overview

This class needs:

  • Documentation

  • Work! Not all types of attlists are intelligently parsed, so we just

spew back out what we get in. This works, but it would be better if we formatted the output ourselves.

AttlistDecls provide just enough support to allow namespace declarations. If you need some sort of generalized support, or have an interesting idea about how to map the hideous, terrible design of DTD AttlistDecls onto an intuitive Ruby interface, let me know. I’m desperate for anything to make DTDs more palateable.

Class Method Summary

Child - Inherited

.new

Constructor.

Instance Attribute Summary

Child - Inherited

#next_sibling
#next_sibling=

Sets the next sibling of this child.

#parent

The Parent of this object.

#parent=

Sets the parent of this child to the supplied argument.

#previous_sibling
#previous_sibling=

Sets the previous sibling of this child.

Node - Included

Instance Method Summary

Child - Inherited

#bytes

This doesn’t yet handle encodings.

#document
Returns

the document this child belongs to, or nil if this child belongs to no document.

#remove

Removes this child from the parent.

#replace_with

Replaces this object with another object.

Node - Included

#each_recursive

Visit all subnodes of self recursively.

#find_first_recursive

Find (and return) first subnode (recursively) for which the block evaluates to true.

#indent,
#index_in_parent

Returns the position that self holds in its parent’s array, indexed from 1.

#next_sibling_node, #previous_sibling_node,
#to_s
indent

Constructor Details

.new(source) ⇒ AttlistDecl

Create an AttlistDecl, pulling the information from a Source. Notice that this isn’t very convenient; to create an AttlistDecl, you basically have to format it yourself, and then have the initializer parse it. Sorry, but for the foreseeable future, DTD support in ::REXML is pretty weak on convenience. Have I mentioned how much I hate DTDs?

[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 29

def initialize(source)
  super()
  if (source.kind_of? Array)
    @element_name, @pairs, @contents = *source
  end
end

Instance Attribute Details

#element_name (readonly)

What is this? Got me.

[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 22

attr_reader :element_name

Instance Method Details

#[](key)

Access the attlist attribute/value pairs.

value = attlist_decl[ attribute_name ]
[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 38

def [](key)
  @pairs[key]
end

#each(&block)

Iterate over the key/value pairs:

attlist_decl.each { |attribute_name, attribute_value| ... }
[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 50

def each(&block)
  @pairs.each(&block)
end

#include?(key) ⇒ Boolean

Whether an attlist declaration includes the given attribute definition

if attlist_decl.include? "xmlns:foobar"
[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 44

def include?(key)
  @pairs.keys.include? key
end

#node_type

[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 59

def node_type
  :attlistdecl
end

#write(out, indent = -1)

Write out exactly what we got in.

[ GitHub ]

  
# File 'lib/rexml/attlistdecl.rb', line 55

def write out, indent=-1
  out << @contents
end