2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-06-09 21:31:01 -04:00
|
|
|
#vim:ts=2 sw=2 noexpandtab:
|
2018-11-02 13:52:33 -04:00
|
|
|
require_relative 'child'
|
|
|
|
require_relative 'source'
|
2003-06-09 21:31:01 -04:00
|
|
|
|
|
|
|
module REXML
|
2008-10-01 09:46:53 -04:00
|
|
|
# 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
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# What is this? Got me.
|
|
|
|
attr_reader :element_name
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# 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.
|
2015-06-13 21:13:33 -04:00
|
|
|
# Sorry, but for the foreseeable future, DTD support in REXML is pretty
|
2008-10-01 09:46:53 -04:00
|
|
|
# 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
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# Access the attlist attribute/value pairs.
|
|
|
|
# value = attlist_decl[ attribute_name ]
|
|
|
|
def [](key)
|
|
|
|
@pairs[key]
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# Whether an attlist declaration includes the given attribute definition
|
|
|
|
# if attlist_decl.include? "xmlns:foobar"
|
|
|
|
def include?(key)
|
|
|
|
@pairs.keys.include? key
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# Iterate over the key/value pairs:
|
|
|
|
# attlist_decl.each { |attribute_name, attribute_value| ... }
|
|
|
|
def each(&block)
|
|
|
|
@pairs.each(&block)
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
# Write out exactly what we got in.
|
|
|
|
def write out, indent=-1
|
|
|
|
out << @contents
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2008-10-01 09:46:53 -04:00
|
|
|
def node_type
|
|
|
|
:attlistdecl
|
|
|
|
end
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|