mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Initial revision
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									ca02190d88
								
							
						
					
					
						commit
						ea7a527a2a
					
				
					 53 changed files with 6674 additions and 0 deletions
				
			
		
							
								
								
									
										62
									
								
								lib/rexml/attlistdecl.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								lib/rexml/attlistdecl.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,62 @@
 | 
			
		|||
#vim:ts=2 sw=2 noexpandtab:
 | 
			
		||||
require 'rexml/child'
 | 
			
		||||
require 'rexml/source'
 | 
			
		||||
 | 
			
		||||
module REXML
 | 
			
		||||
	# 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 AttlistDecl < Child
 | 
			
		||||
		include Enumerable
 | 
			
		||||
 | 
			
		||||
		# What is this?  Got me.
 | 
			
		||||
		attr_reader :element_name
 | 
			
		||||
 | 
			
		||||
		# 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 forseeable future, DTD support in REXML is pretty
 | 
			
		||||
		# weak on convenience.  Have I mentioned how much I hate DTDs?
 | 
			
		||||
		def initialize(source)
 | 
			
		||||
			super()
 | 
			
		||||
			if (source.kind_of? Array)
 | 
			
		||||
				@element_name, @pairs, @contents = *source
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	
 | 
			
		||||
		# Access the attlist attribute/value pairs.
 | 
			
		||||
		#  value = attlist_decl[ attribute_name ]
 | 
			
		||||
		def [](key)
 | 
			
		||||
			@pairs[key]
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# Whether an attlist declaration includes the given attribute definition
 | 
			
		||||
		#  if attlist_decl.include? "xmlns:foobar"
 | 
			
		||||
		def include?(key)
 | 
			
		||||
			@pairs.keys.include? key
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# Itterate over the key/value pairs:
 | 
			
		||||
		#  attlist_decl.each { |attribute_name, attribute_value| ... }
 | 
			
		||||
		def each(&block)
 | 
			
		||||
			@pairs.each(&block)
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		# Write out exactly what we got in.
 | 
			
		||||
		def write out, indent=-1
 | 
			
		||||
			out << @contents
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		def node_type
 | 
			
		||||
			:attlistdecl
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue