I'm trying to parse the following XML with the following jQuery. Nothing is displayed on the page. I know it's getting the file. I've looked online and though there are many examples of parsing xml with jquery none of them looked like this formatting.
XML:
<?xml version="1.0" encoding="utf-8"?>
<wcm:root xmlns:wcm="http://www.stellant.com/wcm-data/ns/8.0.0" version="8.0.0.0">
<wcm:element name="title"></wcm:element>
<wcm:element name="wide_image"><img src='[!--$wcmUrl&amp;x28;'resource&#39;,&#39;CMS3_130980&#39;&amp;x29;--]&#39;/></wcm:element>
<wcm:element name="image"><img src="[!--$wcmUrl('resource','CMS3_132821')--]"/></wcm:element>
<wcm:element name="body"><p>
Paragraph of text goes here.<br /><br />
Paragraph of text goes here.<br /><br />
Paragraph of text goes here.<br /><br />
Paragraph of text goes here.<br /><br />
Paragraph of text goes here.</p>
</wcm:element>
</wcm:root>
HTML & jQuery:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "link_to_my_file.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml){
$(xml).find("wcm\\3a root").each(function(){
alert("Test");
$("#output").append($(this).attr("title") + "<br />");
$("#output").append($(this).attr("wide_image") + "<br />");
$("#output").append($(this).attr("image") + "<br />");
$("#output").append($(this).attr("body") + "<br />");
});
};
</script>
<div id="output"></div>
</html>
You have to escape the
:
in the selector: http://mothereff.in/css-escapes#1wcm%3ArootSo, instead of:
Use:
Also, your code snippet is invalid JavaScript (missing
}
after theparseXml
function declaration). Check your error console.