Closed
Bug 393192
Opened 18 years ago
Closed 18 years ago
XML, xmlns attribut and createElementNS
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: lukas, Unassigned)
References
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9a7) Gecko/2007080210 GranParadiso/3.0a7
I'm unable to set attrinute "xmlns" for tag in XML document in GranParadiso.
In FFox2 I was using setAttribute('xmlns',value) this way doesn't work now so I have to switch to createElementNS(namespace,'elm') BUT If I do this then FFox3 adds xmlns="" attribute to ALL CHILD NODES of <elm> (FFox2 works ok)
There is small example of the same XML document generated in FFox2 and 3a7 by combination of createElement() and createElementNS()
FFox 2
<?xml version="1.0" encoding="utf-8" ?>
<iq type="get">
<query xmlns="webmail:iq:private">
<resources>
<login_settings/>
</resources>
</query>
</iq>
FFox 3
<?xml version="1.0" encoding="utf-8" ?>
<iq type="get">
<query xmlns="webmail:iq:private"> <-- created by createElementNS();
<resources xmlns=""> <-- created by createElement();
<login_settings/> <-- created by createElement();
</resources>
</query>
</iq>
FFox 3
<?xml version="1.0" encoding="utf-8" ?>
<iq type="get">
<query> <-- created by createElement(); + setAttribute('xmlns',value) = no attribute at all
Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Expected Results:
setAttribute('xmlns') allowed OR no xmlns in child tags in case of using createElementNS
Comment 1•18 years ago
|
||
Same Problem in XULRUnner Mozilla/5.0 (Windows; U; Windows NT 5.1; en-EN; rv:1.9a6pre) Gecko/20070624
Comment 2•18 years ago
|
||
I can reproduce this in latest XULRunner. All direct child elements of the element created with createElementNS have that empty xmlns attribute.
Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9b2pre) Gecko/2007111510
I vote for both:
Allow setAttribute("xmlns") AND don't add an empty xmlns attribute in child elements.
Comment 3•18 years ago
|
||
Checking for the xmlns attribute with hasAttribute("xmlns") always returns false for both the element created using createElementNS and the direct children.
Using removeAttribute(xmlns) doesn't work as either. This is very irritating.
BTW: This is no Firefox only problem.
Comment 4•18 years ago
|
||
This looks invalid to me. According to the DOM spec, elements created with createElement do not have any namespace URI. So on serialising the DOM the xmlns="" on the elements is just ensuring that, without the xmlns they would be in the same namespace as the parent element. If you created them with the same namespace as the parent then they should have no xmlns on them.
The xmlns attribute doesn't really exist in the in-memory DOM tree since it isn't an attribute as such.
Comment 5•18 years ago
|
||
As Mossop points out: if you use createElement the element has no namespace, so we have to insert the empty xmlns attribute to make the serialization correspond to the DOM (and yes, FF2 was suffering from bug 301260). The DOM spec doesn't allow setting xmlns attributes or changing the namespace of an element.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
Comment 6•18 years ago
|
||
When creating sub elements to an element that should not have any xmlns attribute, just use createElementNS again with the same namespace as it's parent.
So old scripts like
var e = doc.createElement("foo");
e.setAttribute('xmlns', 'http://www.foo.org/');
var child = doc.createElement("bar");
e.appendChild(child);
Should now look like
var e = doc.createElementNS('http://www.foo.org/',"foo");
var child = doc.createElementNS('http://www.foo.org/',"bar");
e.appendChild(child);
Than the child has no xmlns attribute but it's parent has.
| Reporter | ||
Comment 7•18 years ago
|
||
I agree with Daniel Kirsch.
I dont care about createElementNS. I want to use createElement + setAttribute like in MSIE and Opera, FFox1.5, FFox2. I dont care if any XML/XULparser in ffox use this attribute or not. I just wanna create XML Doc and post it thru HTTPrequest to our server.
Whatever, creating element with attribute xmlns="" is NOT VALID. FFox3 is the only browser with this behaviour.
Im AJAX/PHP Developer for many years and Im relly tired by such stupid bugs. Things like Eval in public scope which suddenly doesnt work in FFox3 thru window.eval() and so. What are you doing people? How many stupid hacks we have to use to create simple app for all version of FFox. :-/
Comment 8•18 years ago
|
||
(In reply to comment #7)
> I agree with Daniel Kirsch.
Well, actually I understand why they changed that behaviour now and why setting the attribute directly isn't allowed anymore. While this is irritating at first it is logical and save.
I now use createElementNS which is the proper way to create elements in a special namespace. The parser does everything else and it seems to work very nicely.
So I now agree to set this invalid (and go back to rewrite a lot of code).
Comment 10•17 years ago
|
||
this will break with many existing applications...
Comment 11•17 years ago
|
||
> According to the DOM spec, elements created with
> createElement do not have any namespace URI.
But, this doesn't mean they have empty (or root) URI. This is nonsense. By setting xmlns='' you set the NamespaceURI in opposite to DOM spec. Not to set xmlns is the right way, because the element will become part of a namespace in appendChild(), not in createElement().
You need to log in
before you can comment on or make changes to this bug.
Description
•