views:

126

answers:

1

I use javascript xpath queries (document.evaluate(...)) to read and modify parts of xml/svg/html documents.

Setting the nodeValue of queried element and text nodes is no problem. but when setting attribute values, it is indeed set, but not reflected on the attribute DOM Node.

It looks like xpath queries for attribute nodes return (name,value) pairs and not the attribute node.

Why is it so?

How can I circumvent it?

+1  A: 

Abit of code would help immensely and what browser are you doing it in? I used this simple HTML code and was able to change the attribute quite happily in FF 3.5.

<html>
<body>
<img src="Jellyfish.jpg"/>
<script>
    var node = document.evaluate("//img/@src", document, null, XPathResult.ANY_TYPE, null);
    var val = node.iterateNext();
    val.textContent = "Desert.jpg";
</script>
</body>
</html>
tyranid