Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/rexml/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def element=( element )
#
# This method is usually not called directly.
def remove
@element.attributes.delete self.name unless @element.nil?
@element.attributes.delete self unless @element.nil?
end

# Writes this attribute (EG, puts 'key="value"' to the output)
Expand All @@ -205,6 +205,15 @@ def xpath
def document
@element&.document
end

# Returns true if this attribute is a namespace declaration, false otherwise.
# "foo" => false
# "xmlns" => true
# "xmlns:foo" => true
# "foo:xmlns" => false
def namespace_declaration?
prefix == 'xmlns' || (prefix.empty? && name == 'xmlns')
end
end
end
#vim:ts=2 sw=2 noexpandtab:
27 changes: 15 additions & 12 deletions lib/rexml/doctype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,26 @@ def node_type
end

def attributes_of element
rv = []
each do |child|
child.each do |key,val|
rv << Attribute.new(key,val)
end if child.kind_of? AttlistDecl and child.element_name == element
raw_attributes = _attlist_mappings[element] || {}
raw_attributes.map do |key, value|
Attribute.new(key, value)
end
rv
end

def attribute_of element, attribute
att_decl = find do |child|
child.kind_of? AttlistDecl and
child.element_name == element and
child.include? attribute
_attlist_mappings[element]&.[](attribute)
end

def _attlist_mappings
mapping = {}
grep(AttlistDecl).each do |child|
raw_attributes = mapping[child.element_name] ||= {}
child.each do |key, val|
# First declaration wins
raw_attributes[key] = val unless raw_attributes.key? key
end
end
return nil unless att_decl
att_decl[attribute]
mapping
end
Comment on lines +126 to 136

def clone
Expand Down
Loading
Loading