We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

Read xml file to an array

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
soso
Posts: 62
Joined: Tue Apr 22, 2008 8:11 am

Read xml file to an array

Post by soso »

Hi,

I've a problem to read a xml file with data tag.

I use this code:

Code: Select all

            <data name="call" src="D:\My Documents\Visual Studio 2005\Projects\Test\msg.xml" maxage="0"/>
            <script>
                var rc = call.documentElement.getElementsByTagName("rc").item(0).firstChild.data;
                var msg= call.documentElement.getElementsByTagName("msg").item(0).firstChild.data;
				var msg1= call.documentElement.getElementsByTagName("msg").item(1).firstChild.data;
	        </script>
My xml file is like this:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<call>
    <rc>0</rc>
    <message>D:\media\-57672070.vox</message>
    <message>media/lastcall.wav</message>
</call>
I would like to use an array to read all msg in xml files with tag "message".

How can I proceed?

Thanks.

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

IVR servers do not access local hard drives

Post by support »

Hi soso,

As a starting point, you will not be able to use URL's like D:\My Documents\... because our IVR servers do not have access to your local hard drives.

To access all elements with a certain tagname and store their contents in an array, you can utilize the fact that getElementsByTagName returns an array-like structure of DOM elements. Refer to http://www.w3.org/TR/2004/WD-voicexml21 ... c-data-dom for information on what DOM functions are available.

Code: Select all

<script>
var messages = call.documentElement.getElementsByTagName("message");
var array = [];
for (var i = 0; i < messages.length; i++) { 
    array[] = messages.item(i).firstChild().toString(); 
}
</script>
Last edited by support on Tue Dec 22, 2009 5:50 pm, edited 1 time in total.

soso
Posts: 62
Joined: Tue Apr 22, 2008 8:11 am

Post by soso »

Ok, thanks.

Yes, I change the local file for yours servers.

Thanks for your code. It's ok.

I've another problem: how can I play each element from array (I try "foreach" but doesn't work)?

Thanks by advance.

soso
Posts: 62
Joined: Tue Apr 22, 2008 8:11 am

Post by soso »

Ok, I found the solution. I use this code:

Code: Select all

            <foreach array="array" item="tmp">
                <audio expr="tmp" />
            </foreach>
Thanks again.

Post Reply