1

I am trying to process XML data received from an API in VXML. The request is made using element. I am able to retrieve nodeNames from the XML object, but nodeValues are empty.

Function used to process xml data:

<script>
    <![CDATA[
        function xmlToJson(root) {

            var nodes = root.childNodes;
            var res= {};

            for(var i=0; i<nodes.length; i++) {
                res[nodes.item(i).nodeName] = nodes.item(i).nodeValue;
            }
            return res;

        };
    ]]>     

    </script>

VXML code:

<block>
            <data name="xmlData" src="/getJSON" />
            <var name="root" expr="xmlData.documentElement"/>
            <var name = "cleanData" expr = "xmlToJson(root)" />

            <log label="HrushikeshPracticeIvr|Index.jsp" expr="cdrkey"> XML to JSON::: <value expr = "cleanData" /> </log>

            <exit />
        </block>

Output from VXI browser:

Jan 2 12:16:09.30|47201006917376|3|8001|com.aumtechinc.vxi|[label:HrushikeshPracticeIvr|Index.jsp] [expr:null] XML to JSON::: { (birthDate, ), (firstName, ), (id, ), (lastName, ), (version, ) }

I have referred following source for above code implementation: https://www.w3.org/TR/voicexml21/#sec-data-dom

1 Answers1

1

Double check the contents of the returned XML. Most of the VoiceXML browsers I've used will create additional child nodes if there is white space around the value (e.g. spaces, carriage returns, line feeds).

Jim Rush
  • 4,143
  • 3
  • 25
  • 27