E4X: can't use "delete" with filter

B

Bob Tinsman

This problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2.

I've found that if I have an XML node expression that ends in a filter,
I can't use it with the delete operator. In the following example, the
delete operation has no effect:

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
alert(z.foo.(@a == '2'));
delete z.foo.(@a == '2');

even though the expression is valid. I've come up with the following
grim-looking workaround:

function deleteNodes(node, expr) {
for each (i in eval('node.' + expr)) {
eval('delete node.' + expr + '[0]');
}
}

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
deleteNodes(z, "foo.(@a == '2')");

which does what I want.

Is this by design? It's really annoying that I can't use delete this
way. The problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2. I've
found that if I have an XML node expression that ends in a filter,
I can't use it with the delete operator. In the following example, the
delete operation has no effect:

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
alert(z.foo.(@a == '2'));
delete z.foo.(@a == '2');

even though the expression is valid. I've come up with the following
grim-looking workaround:

function deleteNodes(node, expr) {
for each (i in eval('node.' + expr)) {
eval('delete node.' + expr + '[0]');
}
}

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
deleteNodes(z, "foo.(@a == '2')");

which does what I want.

Is this by design? It's really annoying that I can't use delete this
way. The problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2.
 
V

VK

Bob said:
This problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2.

I've found that if I have an XML node expression that ends in a filter,
I can't use it with the delete operator. In the following example, the
delete operation has no effect:

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
alert(z.foo.(@a == '2'));
delete z.foo.(@a == '2');

even though the expression is valid. I've come up with the following
grim-looking workaround:

function deleteNodes(node, expr) {
for each (i in eval('node.' + expr)) {
eval('delete node.' + expr + '[0]');
}
}

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
deleteNodes(z, "foo.(@a == '2')");

which does what I want.

Is this by design? It's really annoying that I can't use delete this
way. The problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2. I've
found that if I have an XML node expression that ends in a filter,
I can't use it with the delete operator. In the following example, the
delete operation has no effect:

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
alert(z.foo.(@a == '2'));
delete z.foo.(@a == '2');

even though the expression is valid. I've come up with the following
grim-looking workaround:

function deleteNodes(node, expr) {
for each (i in eval('node.' + expr)) {
eval('delete node.' + expr + '[0]');
}
}

var z = <abc><foo a='1'>1</foo><foo a='2'>2</foo></abc>;
deleteNodes(z, "foo.(@a == '2')");

which does what I want.

Is this by design? It's really annoying that I can't use delete this
way. The problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2.

Congratulations: you are the first person in the history of this group
who's trying to use this new stuff :)

Not extremely helpful but:
1) E4X is only *partially* implemented in latest Gecko.
2) To fully enable all implemented parts (which is still not full E4X)
use
<script type="text/javascript;e4x=1">
3) AFAICT Mozilla does everything literally as spelled in ECMA, so
reading
<http://www.ecma-international.org/publications/standards/Ecma-357.htm>
may be helpful.
4) I guess bugzilla.mozilla.org is currently being filled up by freshly
discovered E4X bugs. By searching "E4X" you may get some immediate
answers.

My lack of E4X knowledge doesn't allow to answer to your direct
question. Hopefully someone can be more useful.
 
M

Martin Honnen

Bob Tinsman wrote:

I've found that if I have an XML node expression that ends in a filter,
I can't use it with the delete operator.

Does this example approach

var gods = <gods><god name="Kibo" /><god name="Jaffo" /><god name="Xibo"
/></gods>;
for each (var god in gods.god.(@name.indexOf('ibo') != -1)) {
delete gods.god[god.childIndex()];
}

help?

That way you iterate over the XML objects the filter finds and then
delete them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top