Plox
28th August 2013, 19:33
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
console.log(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 = ""
console.log("\n")
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) {
showRequestInfo(a.childNodes[ii].nodeName);
}
}
}
doc.open("POST", 'http://www.example.com/mydata.xml');
doc.send();
}
}
}
}
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:
is-admin
#text
signature
#text
restrictions
#text
How can I fix this and manage to save the information retrieved with the xml document into strings?
Thanks a LOT in advance!
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
console.log(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 = ""
console.log("\n")
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) {
showRequestInfo(a.childNodes[ii].nodeName);
}
}
}
doc.open("POST", 'http://www.example.com/mydata.xml');
doc.send();
}
}
}
}
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:
is-admin
#text
signature
#text
restrictions
#text
How can I fix this and manage to save the information retrieved with the xml document into strings?
Thanks a LOT in advance!