Getting XML document from server and extracting strings from it

  • Good day fellow programmers,

    I am trying to communicate with a rest API web service, get a xml document and then parse it's values into strings.
    Since I am new to this topic any help would be greatly appreciated!

    This is what I built using the XMLHTTPREQUEST example:
    @import QtQuick 2.0

    Rectangle {
    width: 350; height: 400

    function showRequestInfo(text)  {
        log.text = log.text + "\n" + text
    Text  { id: log; anchors.fill: parent; anchors.margins: 10 }
    Rectangle  {
        id: button
        anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom; anchors.margins: 10
        width: buttonText.width + 10; height: buttonText.height + 10
        border.width: mouseArea.pressed ? 2 : 1
        radius : 5; smooth: true
        Text  { id: buttonText; anchors.centerIn: parent; text: "Request" }
        MouseArea  {
            id: mouseArea
            anchors.fill: parent
            onClicked:  {
                log.text = ""
                var doc = new XMLHttpRequest();
                doc.onreadystatechange = function()  {
                                    if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED)  {
                                    } else if (doc.readyState == XMLHttpRequest.DONE)  {
                                      var a = doc.responseXML.documentElement;
                                      for (var ii = 0; ii < a.childNodes.length; ++ii)  {
      "POST", '');


    This code does successfully communicate with the server and retrieves information from it.
    The problem is that it only names the node's name but leaves the values out.

    Example response:


    How can I fix this and manage to save the information retrieved with the xml document into strings?

    Thanks a LOT in advance!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.