setText with variable containing xml

Hi All,

I need the javascript equivalent of:

<c:setText destination="$soapobject//test" select="'test'" mode="replaceChildren"/>

This piece of code puts 'test' inside the xml element test inside the variable soapobject.

I tried to do the following:

bb.command.setText(soapobject.getElementById('test'),'test','replaceChildren');

But this didn't work.

Any suggestions?

Lesley

Hi burger.lj Because "//"

Hi burger.lj

Because "//" xpath expression select one node or more nodes , you have to use for loop otherwise it shows error.You can try the following example :)

<e:handler event="click" type="text/javascript"><![CDATA[
....
var xpath= soapobject.selectNodes(".//test");
for( var i=0;i < xpath.length; i++){
bb.command.setText(xpath[i],'test','replaceChildren');
}
...
]]></e:handler>

hi yudi

Hi Yudi,

Thanks for your reply.
I tested your code, but xpath[i] stays 'null'.

Do you have any idea why this could happen?

Thanks,

Lesley

xpath[i] stays 'null'

Hi burger.lj,

It happens because it does not recognize the "soapobject" variable.The "xpath" itself comes from the "soapobject".That's why it said xpath[i] is null. You can debug the variable, if you want to check whether the variable is there or not by using alert(soapobject)or console.info(soapobject).

Hope this help,

Yudi

How do I alert an element inside soapobject?

Hi Yudi,

Alerting soapobject works now (serialization did the trick).
If I alert soapobject, the alertbox displays [object]. If I serialize soapobject, the alertbox displays the xml.

Now I want to alert one element from soapobject.
Let's say soapobject//test. Without serialization, it displays 'null'. With serialization it says '' (nothing).

How do I get the value of soapobject//test? (it is not empty)

Thanks,

Lesley

Example

Hi Lesley,

Take a look at this code:

<e:variable name="xmldata"><e:data><root><node><childNode /><targetNode /></node></root></e:data></e:variable>

<b:button>
        Click Me
        <e:handler event="click" type="application/javascript"><![CDATA[
                // Baseline
                alert(bb.xml.serialize(xmldata));


                // Set the text
                bb.command.setText(bb.evaluateSmart('.//targetNode', xmldata), 'Text to insert', 'replaceChildren');
                alert(bb.xml.serialize(xmldata));


                // Alert the text
                alert(bb.evaluateSmart('string(.//targetNode)', xmldata));
        ]]></e:handler>
</b:button>

It works

Hi James,

It works now. I just had to change xmldata into vars['xmldata'].

Thanks for your help,

Lesley

Hmm... I don't have any idea

Hmm... I don't have any idea for that... But You may check this http://www.pageresource.com/jscript/index.html tutorials... There I saw something like this. Good luck!