I’m trying to parse an XMLRPC response using jQuery to create a table containing the contents of an array of structs. The response looks like this:
<?xml version="1.0"?>
<methodResponse><params><param><value><array><data>
<value><struct><member><name>time</name><value>1315415195</value></member><member><name>level</name><value>DEBUG</value></member><member><name>thread</name><value>0x805e558</value></member><member><name>message</name><value>glib_syslog_get_log_messages</value></member></struct></value>
<value><struct><member><name>time</name><value>1315415160</value></member><member><name>level</name><value>DEBUG</value></member><member><name>thread</name><value>backup-Backups</value></member><member><name>message</name><value>Sleeping 5 minutes</value></member></struct></value>
....
</data></array></value></param></params></methodResponse>
I then parse the response in my callback function. The first fine works great and finds all the struct elements in the response. The 2nd find is attempting to find the value of the member with the name time, but instead just returns the struct element again. What is the correct selector for “Find me the text of the value element of the member with the name X?”
function loadStatusDone(data) {
if(!data) {
return;
}
//first, must clean the content viewer
$("table#tableStatus tbody").children().remove();
$(data).find('struct').each(function(){
var ts = $(this).find("member name:contains(time) :parent value").text();
var level = "level";
var thread = "thread";
var message = "some message";
var html = "<tr>" +
"<td>" + ts + "</td>" +
"<td>" + level + "</td>" +
"<td>" + thread + "</td>" +
"<td>" + message + "</td>" +
"</tr>";
$("table#tableStatus tbody").append(html);
$("table").trigger("update");
});
}
You can split up
into:
That will select the
namenode with"time"as the text, then get its parent (which is the containing member node). Then use the member node as the context of where to get thevaluenode and return the text of it. I tested this on your XML and it seems to work for me.My Test Code