class Phlex::SGML

def __nested_attributes__(attributes, base_name, buffer = +"")

This allows us to skip many of the checks the `__attributes__` method must perform.
Provides the nested-attributes case for serializing out attributes.
def __nested_attributes__(attributes, base_name, buffer = +"")
	attributes.each do |k, v|
		next unless v
		name = case k
			when String then k
			when Symbol then k.name.tr("_", "-")
			else raise Phlex::ArgumentError.new("Attribute keys should be Strings or Symbols")
		end
		if name.match?(/[<>&"']/)
			raise Phlex::ArgumentError.new("Unsafe attribute name detected: #{k}.")
		end
		case v
		when true
			buffer << " " << base_name << name
		when String
			buffer << " " << base_name << name << '="' << v.gsub('"', "&quot;") << '"'
		when Symbol
			buffer << " " << base_name << name << '="' << v.name.tr("_", "-").gsub('"', "&quot;") << '"'
		when Integer, Float
			buffer << " " << base_name << name << '="' << v.to_s << '"'
		when Hash
			__nested_attributes__(v, "#{base_name}#{name}-", buffer)
		when Array
			buffer << " " << base_name << name << '="' << __nested_tokens__(v) << '"'
		when Set
			buffer << " " << base_name << name << '="' << __nested_tokens__(v.to_a) << '"'
		when Phlex::SGML::SafeObject
			buffer << " " << base_name << name << '="' << v.to_s.gsub('"', "&quot;") << '"'
		else
			raise Phlex::ArgumentError.new("Invalid attribute value #{v.inspect}.")
		end
		buffer
	end
end