Поиск по этому блогу

пятница, 11 июля 2014 г.

prgrmmng

Hello there.
Some time ago i had a problem at work with some programming (xml + javascript + IE v.doesntmatterithink).
Imagine: I have a part of xml like:

<id name="REQUEST">
<d l="en">buddy</d>
<d l="us">bro</d>
</id>
and I need to change values, in this example, "buddy" and "bro". So first thing you can do is to use .nodeValue = "insertnewtext", and this method is working well; this is code:
idNode[i].childNodes[1].childNodes[0].nodeValue = "newvaluehere";
But then i met the problem: .nodeValue doesn't work if previous value is null or doesn't exist, i mean, my xml looks like:

<id name="REQUEST">
<d l="en"></d>
<d l="us"></d>
</id>

I spent hours into web and finally found new way: idNode[i].childNodes[0].text = "newvaluehere". And it works for nulls!

(Maybe i'm dumb, but finding the answer was important to me so i left this note...)