When I execute the following script all I see are the comma's and no nodeValues. What am I missing? Also is there a way to write the output to a file?
<head >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>XML Parsing With jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "Missions.xml",
dataType: ($.browser.msie) ? "text" : "xml",
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#output").append(XMLHttpRequest.responseText + "<br />TextStatus: " +
textStatus + "<br />ErrorThrown: " + errorThrown);
},
success: parseXml
});
});
//print the date followed by the title of each Mission
function parseXml(xml)
{
$(xml).find("Mission").each(function()
{
$("#output").append($(this).find("ID").text());
$("#output").append("," + $(this).find("OrgID").text());
$("#output").append("," + $(this).find("Name").text());
$("#output").append("," + $(this).find("Date").text());
$("#output").append("," + $(this).find("nTouched").text());
$("#output").append("," + $(this).find("HowTouched").text() + "<br />");
});
}
</script>
</head>
<body><div id="output"></div></body>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>XML Parsing With jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "Missions.xml",
dataType: ($.browser.msie) ? "text" : "xml",
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#output").append(XMLHttpRequest.responseText + "<br />TextStatus: " +
textStatus + "<br />ErrorThrown: " + errorThrown);
},
success: parseXml
});
});
//print the date followed by the title of each Mission
function parseXml(xml)
{
$(xml).find("Mission").each(function()
{
$("#output").append($(this).find("ID").text());
$("#output").append("," + $(this).find("OrgID").text());
$("#output").append("," + $(this).find("Name").text());
$("#output").append("," + $(this).find("Date").text());
$("#output").append("," + $(this).find("nTouched").text());
$("#output").append("," + $(this).find("HowTouched").text() + "<br />");
});
}
</script>
</head>
<body><div id="output"></div></body>
07/28/2011 - 09:58
Can you attach some example XML?
Add Comment
[language] [/language]
Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]
See here for supported languages.
Javascript must be enabled to submit anonymous comments - or you can login.