E4X setNamespace not working
Posted: Thu Oct 06, 2011 2:43 pm
I am trying to generate an XML using E4x in Servoy 5.2.4.
Until this, the code works fine. But when I actually want to use the namespace in the <foo/> node, using:
It throws the following error:
How is this possible? As far as I can see on the internet, this should be the way to do it. Or am I missing something?
I can get it to work using this code:
But I need to do it for multiple items in a loop so this approach won't work as it will overwrite the existing node. Anyone have experience with this?
- Code: Select all
var xml = <root><foo/></root>;
var ns = new Namespace('ns','http://example.org/');
xml.addNamespace(ns);
xml.foo = 'bar';
application.output(xml.toXMLString());
Until this, the code works fine. But when I actually want to use the namespace in the <foo/> node, using:
- Code: Select all
var xml = <root><foo/></root>;
var ns = new Namespace('ns','http://example.org/');
xml.addNamespace(ns);
xml.foo = 'bar';
xml.foo.setNamespace(ns);
application.output(xml.toXMLString());
It throws the following error:
- Code: Select all
NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
> org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
How is this possible? As far as I can see on the internet, this should be the way to do it. Or am I missing something?
I can get it to work using this code:
- Code: Select all
xml.ns::foo = 'bar';
But I need to do it for multiple items in a loop so this approach won't work as it will overwrite the existing node. Anyone have experience with this?