* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / lib / rexml / attlistdecl.rb
blobef4721b5ce8d9d27309c874da1c79fb40ae0c41b
1 #vim:ts=2 sw=2 noexpandtab:
2 require 'rexml/child'
3 require 'rexml/source'
5 module REXML
6         # This class needs:
7         # * Documentation
8         # * Work!  Not all types of attlists are intelligently parsed, so we just
9         # spew back out what we get in.  This works, but it would be better if
10         # we formatted the output ourselves.
11         #
12         # AttlistDecls provide *just* enough support to allow namespace
13         # declarations.  If you need some sort of generalized support, or have an
14         # interesting idea about how to map the hideous, terrible design of DTD
15         # AttlistDecls onto an intuitive Ruby interface, let me know.  I'm desperate
16         # for anything to make DTDs more palateable.
17         class AttlistDecl < Child
18                 include Enumerable
20                 # What is this?  Got me.
21                 attr_reader :element_name
23                 # Create an AttlistDecl, pulling the information from a Source.  Notice
24                 # that this isn't very convenient; to create an AttlistDecl, you basically
25                 # have to format it yourself, and then have the initializer parse it.
26                 # Sorry, but for the forseeable future, DTD support in REXML is pretty
27                 # weak on convenience.  Have I mentioned how much I hate DTDs?
28                 def initialize(source)
29                         super()
30                         if (source.kind_of? Array)
31                                 @element_name, @pairs, @contents = *source
32                         end
33                 end
34         
35                 # Access the attlist attribute/value pairs.
36                 #  value = attlist_decl[ attribute_name ]
37                 def [](key)
38                         @pairs[key]
39                 end
41                 # Whether an attlist declaration includes the given attribute definition
42                 #  if attlist_decl.include? "xmlns:foobar"
43                 def include?(key)
44                         @pairs.keys.include? key
45                 end
47                 # Iterate over the key/value pairs:
48                 #  attlist_decl.each { |attribute_name, attribute_value| ... }
49                 def each(&block)
50                         @pairs.each(&block)
51                 end
53                 # Write out exactly what we got in.
54                 def write out, indent=-1
55                         out << @contents
56                 end
58                 def node_type
59                         :attlistdecl
60                 end
61         end
62 end