-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
XML library: Element in no namespace assigned to parent element namespace #1784
Comments
Good point. I simply didn't take this situation into account when designing how to strip namespaces. According to this Oracle doc it ought to be possible to undeclare the default namespace with
Does that sound good to you @akloeber? Registering namespace prefixes sounds like a valid enhancement request but requires a separate issue, preferably backed by a pull request. |
Assuming adding diff --git a/src/robot/libraries/XML.py b/src/robot/libraries/XML.py
index abc0126..e208d5d 100644
--- a/src/robot/libraries/XML.py
+++ b/src/robot/libraries/XML.py
@@ -1324,6 +1324,9 @@ class NameSpaceStripper(object):
if ns != current_ns:
elem.attrib['xmlns'] = ns
current_ns = ns
+ elif current_ns:
+ elem.attrib['xmlns'] = ''
+ current_ns = None
for child in elem:
self.strip(child, current_ns) |
Unfortunately this is only a simplified example. In our setup the XML we'd like to check is server generated and hence we do not have control over its structure. |
Is there a reason |
Assuming I understand xml namespaces correctly, using |
You are right, if default namespaces are explicitely reset the output Am Sonntag, 7. September 2014 schrieb Pekka Klärck :
|
As I noted in the commit message of revision 6515328, this bug affected both the standard etree and lxml modes. In the lxml mode namespace prefixes are preserved correctly, so you may want to use that if prefixes are important. |
Good to know, I'll give it a try. Thanks for your support!! |
When using the default XML namespace stripping (i.e.
keep_clark_notation
not set) namespaces can become corrupted as demonstrated in the following example:The output becomes:
In the input the
<bar>
element has no namespace as there is no namespace prefix on the<bar>
element itself and no default namespace is set. In the output the<bar>
element belongs to namespacehttp://example.com/ns0
inherited by the default namespace and therefore the output is no more logically equivalent to the input and thus invalid against the corresponding XML schema.The only way to work around this issue is enabling Clark Notation which makes evaluation of XPaths really hards as already explained in the XML library documentation. Moreover there is no way to register and use namespace prefixes in order to use them in XPaths.
Environment:
Robotframework 2.8.5
Python 2.7.5
Mac OS X 10.9.4
The text was updated successfully, but these errors were encountered: