CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2013

    [RESOLVED] XML to Javascript - Conversion of response.

    results from getpost.php

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sapien nisl, convallis vitae sodales sed, convallis eu nunc. Donec sem libero, semper non tempor non, tincidunt non dui. Phasellus tempus, est quis congue posuere, dolor enim ultricies lectus, ullamcorper porttitor sem nisl eu justo. Morbi ultricies porttitor odio ut eleifend. Integer gravida convallis laoreet. Proin scelerisque, libero sed varius venenatis, turpis nisi malesuada tortor, ac fermentum quam est eu est. Integer semper pellentesque magna, eu molestie tellus porta viverra. Quisque pellentesque fermentum quam et mattis. Praesent lacinia fringilla ipsum, quis rhoncus turpis tristique nec. Donec mollis euismod lacinia. Vestibulum nulla ligula, volutpat nec tincidunt eget, convallis sed ante.
    <datetime>2013-05-12 16:23:56</datetime>

    How do I convert this to be able to use it in my javascript?
    I need it to be in array form or at least in individual variables.

    Sincerely yours,

  2. #2
    Join Date
    Jun 2009

    Re: XML to Javascript - Conversion of response.

    Check out this article on parsing XML in JavaScript. http://www.w3schools.com/xml/xml_parser.asp
    jQuery natively, and through various plug-ins, supports XML and makes it easy to access and analyse.

  3. #3
    Join Date
    Sep 2013

    Re: [RESOLVED] XML to Javascript - Conversion of response.

    Find the script for XML to Array conversion using jquery, Ajax :

    $().ready(function() {
    $("#getXmlRes").click(function(event) {
    $.ajax ({
    url: "./xml/response.xml"

    $(document).ajaxComplete(function(event, response, ajaxOptions) {
    if (ajaxOptions.url == "./xml/response.xml") {
    var xmlDoc = $.parseXML(response.responseText);

    var responseArray = new Array();
    var index = 0;

    //Storing XML response into array
    $(xmlDoc).find("response").each(function() {
    $response = $(this);
    response = new Array();

    response['journalID'] = $response.find('journalID').text();
    response['accountID'] = $response.find('accountID').text();
    response['title'] = $response.find('title').text();
    response['content'] = $response.find('content').text();
    response['datetime'] = $response.find('datetime').text();

    responseArray[index++] = response;

    $('#response').append('<h3>Response :');

    //Retrieving data from array
    for (var i in responseArray) {
    $('#response').append('journalID : ' +responseArray[i]['journalID'] + '<br/>');
    $('#response').append('accountID : ' +responseArray[i]['accountID'] + '<br/>');
    $('#response').append('title : ' +responseArray[i]['title'] + '<br/>');
    $('#response').append('content : ' +responseArray[i]['content'] + '<br/>');
    $('#response').append('datetime : ' +responseArray[i]['datetime'] + '<br/>');


    Hope this will help you..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.