diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rexml/attribute.rb | 21 | ||||
-rw-r--r-- | lib/rexml/element.rb | 4 | ||||
-rw-r--r-- | lib/rexml/xpath_parser.rb | 10 |
3 files changed, 14 insertions, 21 deletions
diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb index 37671cf15f..8933a013a2 100644 --- a/lib/rexml/attribute.rb +++ b/lib/rexml/attribute.rb @@ -67,15 +67,11 @@ module REXML # e.add_attribute( "nsa:a", "aval" ) # e.add_attribute( "b", "bval" ) # e.attributes.get_attribute( "a" ).prefix # -> "nsa" - # e.attributes.get_attribute( "b" ).prefix # -> "elns" + # e.attributes.get_attribute( "b" ).prefix # -> "" # a = Attribute.new( "x", "y" ) # a.prefix # -> "" def prefix - pf = super - if pf == "" - pf = @element.prefix if @element - end - pf + super end # Returns the namespace URL, if defined, or nil otherwise @@ -87,9 +83,8 @@ module REXML # e.attribute("ns:a").namespace # => "http://url" # e.attribute("nsx:a").namespace # => nil # - # TODO: This method should always return nil for no namespace - # attribute. Because the default namespace doesn't apply to - # attribute name. + # This method always returns "" for no namespace attribute. Because + # the default namespace doesn't apply to attribute names. # # From https://www.w3.org/TR/xml-names/#uniqAttrs # @@ -99,10 +94,14 @@ module REXML # e.add_namespace("", "http://example.com/") # e.namespace # => "http://example.com/" # e.add_attribute("a", "b") - # e.attribute("a").namespace # => nil + # e.attribute("a").namespace # => "" def namespace arg=nil arg = prefix if arg.nil? - @element.namespace arg + if arg == "" + "" + else + @element.namespace(arg) + end end # Returns true if other is an Attribute and has the same name and value, diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb index de83ec3b51..c706a7c245 100644 --- a/lib/rexml/element.rb +++ b/lib/rexml/element.rb @@ -1133,8 +1133,8 @@ module REXML elsif old_attr.prefix != value.prefix # Check for conflicting namespaces if value.prefix != "xmlns" and old_attr.prefix != "xmlns" - old_namespace = @element.namespace(old_attr.prefix) - new_namespace = @element.namespace(value.prefix) + old_namespace = old_attr.namespace + new_namespace = value.namespace if old_namespace == new_namespace raise ParseException.new( "Namespace conflict in adding attribute \"#{value.name}\": "+ diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index 47fa4ef84e..321bc481af 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -493,17 +493,11 @@ module REXML if prefix.nil? raw_node.name == name elsif prefix.empty? - # FIXME: This DOUBLES the time XPath searches take - raw_node.name == name and - raw_node.namespace == raw_node.element.namespace + raw_node.name == name and raw_node.namespace == "" else # FIXME: This DOUBLES the time XPath searches take ns = get_namespace(raw_node.element, prefix) - if ns.empty? - raw_node.name == name and raw_node.prefix.empty? - else - raw_node.name == name and raw_node.namespace == ns - end + raw_node.name == name and raw_node.namespace == ns end else false |