By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,490 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,490 IT Pros & Developers. It's quick & easy.

E4X: can't use "delete" with filter

P: n/a
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.

Mar 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK

Bob Tinsman wrote:
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.

Mar 15 '06 #2

P: n/a


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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.