I can't seem to figure out this problem. I am trying to get xml to render html tags. The problem I am having using .text() will display but not recognize any html tags. If I use .html() or just call var long2 = $(this).find('long'); nothing will show up in Safari or IE.
I have xml paragraph I have text in here that needs bold tags or tags which is why i need ht开发者_Go百科ml tags in the xml to be recognized.
Code:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "xml/sites.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('site').each(function(){
var id = $(this).attr('id');
var title = $(this).find('title').text();
var Class = $(this).find('class').text();
$('<div class="'+Class+'" id="link_'+id+'"></div>').html('<p class="title">'+title+'</p>').appendTo('#page-wrap');
$(this).find('desc').each(function(){
var url = $(this).find('url').text();
var long = $(this).find('long').text();
$('<div class="long"></div>').html(long).appendTo('#link_'+id);
$('#link_'+id).append('<a href="http://'+url+'">'+url+'</a>');
var long2 = $(this).find('long');
$('<div class="long2"></div>').html(long2).appendTo('#link_'+id);
});
});
}
});
.html()
does not work with XML documents. You should wrap the HTML content in the XML file with <![CDATA[your code here]]>
.
I once ran into this problem while working with some xslt stuff. Apparently in webkit and some IE versions you cannot parse html that does not comply to your doctype. As such as a node will not be available to jquery. HOWEVER, there is a solution you can make you element query by using the nodename attribute $('[nodeName=long]',xml)
精彩评论