ggalan
08-18-2011, 04:44 PM
i am parsing XML using jQuery like this
$(document).ready(function(){
$.ajax({
type: "GET",
url: "list.xml",
dataType: "xml",
success: parseXml,
error: err
});
});
function err(xhr, reason, ex) { $('#output').append(reason); }
function parseXml(xml){
$(xml).find("entry").each(function(){
$("#output").append($(this).attr("name") +
" | " +
$(this).find("email").text() +
" | " +
$(this).find("score").text() +"<br />");
});
}
my xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<entry name="John Doe">
<email>john.doe@yahoo.com</email>
<score>88</score>
<Date>1/13/2009</Date>
</entry>
<entry name="GI Jane">
<email>g.jane@gmail.com</email>
<score>104</score>
<Date>1/13/2011</Date>
</entry>
<entry name="Joe Smith">
<email>joe.s@hotmail.com</email>
<score>100</score>
<Date>9/13/2010</Date>
</entry>
</data>
my output looks like
John Doe | john.doe@yahoo.com | 88
GI Jane | g.jane@gmail.com | 104
Joe Smith | joe.s@hotmail.com | 100
question: i want to output only those that score 100 or above
what is the best way to go about this? should i push elements into an array and compare those results?
can i somehow write the comparison into the parsing?
function parseXml(xml){
$(xml).find("entry").each(function(){
$("#output").append($(this).attr("name") +
" | " +
$(this).find("email").text() +
" | " +
$(this).find("score").text() +"<br />");
});
}
$(document).ready(function(){
$.ajax({
type: "GET",
url: "list.xml",
dataType: "xml",
success: parseXml,
error: err
});
});
function err(xhr, reason, ex) { $('#output').append(reason); }
function parseXml(xml){
$(xml).find("entry").each(function(){
$("#output").append($(this).attr("name") +
" | " +
$(this).find("email").text() +
" | " +
$(this).find("score").text() +"<br />");
});
}
my xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<entry name="John Doe">
<email>john.doe@yahoo.com</email>
<score>88</score>
<Date>1/13/2009</Date>
</entry>
<entry name="GI Jane">
<email>g.jane@gmail.com</email>
<score>104</score>
<Date>1/13/2011</Date>
</entry>
<entry name="Joe Smith">
<email>joe.s@hotmail.com</email>
<score>100</score>
<Date>9/13/2010</Date>
</entry>
</data>
my output looks like
John Doe | john.doe@yahoo.com | 88
GI Jane | g.jane@gmail.com | 104
Joe Smith | joe.s@hotmail.com | 100
question: i want to output only those that score 100 or above
what is the best way to go about this? should i push elements into an array and compare those results?
can i somehow write the comparison into the parsing?
function parseXml(xml){
$(xml).find("entry").each(function(){
$("#output").append($(this).attr("name") +
" | " +
$(this).find("email").text() +
" | " +
$(this).find("score").text() +"<br />");
});
}