Using XmlListModel to access XmlHttpRequest retrieved remote xml?
Recently learned the way how to parse the http xml response using XmlHttpRequest, but someone mentioned recently in this forum that one could use XmlListModel for such parsing.
Could someone help and describe the logic in a few words like what is the method here to use it?
Basically when the xml is retrieved I could address is without problem via URL, but problem is I don't understand how to tell XmlListModel to wait until the XML is requested and the answer is ready. Is it done via signals or how?
Slocan last edited by
See the example in the documentation here:
In a nutshell, you create a new XmlListModel object, and you set its source property to the URL you want it to fetch. It will do the rest automatically. You can follow its status property to see when the data is still loading or when it is ready. But usually, you associate it with a ListView (or other View item) to display the information it downloads.
Hey Slocan, I know the way XmlListModel works - sorry I was not precise enough:
Problem is that the source XML I am to point XmlListModel to doesn't exist until the remote server gets a xmlhttprequest posted data (api communication process). Once I post proper data to the remote server it replies back code 200 and gives me XML response which I want to parse.
Again I can do it now with XmlHttpRequest but really want to use XmlListModel for the reply...but what should I put as source since the reply doesn't exist on the moment it loads...
Slocan last edited by
In that case, use XmlHttpRequest to do the post and receive the data, and then set the xml property of the XmlListModel with the data you've received. Leave the source property empty.
Hmm thats indeed what i needed;) thanks a lot [SOLVED]
Hmm although I know the approach is right I can';t figure out what is the syntax to pass XML response over to the XmlListModel.
Straightforwardly this one below doesn't work (gives "Cannot assign [undefined] to QString" error )
@var xmlObject = xhr.responseXml;
xmllistmodelparser.xml=xmlObject; console.log("passed to xmlparser")@
How do I convert the xhr.responseXml to be suitable for XmlListModel??
remy_david last edited by
Use responseText instead of responseXml it should work.