-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle unprefixed attributes in Element#attribute
correctly
#151
base: master
Are you sure you want to change the base?
Conversation
Currently, `Element#attrubute` handles unprefixed attributes as attributes with the default namespace, and handles the default namespace as `nil` value. However, it is a mis-interpretation of the specification of XML 1.0. XML 1.0 specification says: (https://www.w3.org/TR/xml-names/#defaulting) > The namespace name for an unprefixed attribute name always has > no value. Therefore, we need to distinguish `nil` and the default namespace. Also, unprefixed attributes should not be handled as attributes with the default namespace. Note that XML 1.0 specification also says: > Default namespace declarations do not apply directly to attribute > names; the interpretation of unprefixed attributes is determined > by the element on which they appear. This means that we can know (programmatically) how to handle unprefixed attributes from the element's namespace. It does not mean that the namespace of an unprefixed attribute becomes the default namespace. This commit changes `Element#attribute` behavior correctly and updates tests for it.
# xml_string = "<root xmlns:a='http://example.com/a' a:x='a:x' x='x'/>" | ||
# document = REXML::Document.new(xml_string) | ||
# document.root.attribute("x") # => x='x' | ||
# document.root.attribute("x", "a") # => a:x='a:x' | ||
# document.root.attribute("x", "http://example.com/a") # => a:x='a:x' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also updated here to make it clear that the namespace
argument takes a namespace URI.
I know the specification (and I know the specification confuses many people) and I can understand this proposal. In this case, it seems that How about adding a new strict version of |
@kou I agree with deprecating |
Then how about documenting this instead of changing the current behavior? |
In many cases, people want to obtain an attribute value, and don't want an |
FYI: We can use |
Currently,
Element#attrubute
handles unprefixed attributes as attributes with the default namespace, and handles the default namespace asnil
value. However, it is a mis-interpretation of the specification of XML 1.0.XML 1.0 specification says:
(https://www.w3.org/TR/xml-names/#defaulting)
Therefore, we need to distinguish
nil
and the default namespace. Also, unprefixed attributes should not be handled as attributes with the default namespace.Note that XML 1.0 specification also says:
This means that we can know (programmatically) how to handle unprefixed attributes from the element's namespace. It does not mean that the namespace of an unprefixed attribute becomes the default namespace.
This commit changes
Element#attribute
behavior correctly and updates tests for it.@kou It breaks backward compatibility, so I'm concerned. What do you think?