I’m not able to get html from a very simple XML file as below. In this case I just get a text string as “mots <i>français</i>” and not a html formatted text as “mots français” :
<content>
<text id="n1">
<fr><![CDATA[mots <i>français</i>]]></fr>
<en><![CDATA[<i>english</i> words]]></en>
</text>
... and so on
</content>
Such xml file using this jQuery script to get strings from XML. Then for every element where I want a different language content, I add a value to a data- attribute (i.e. <p data-langtag=n1> … </p> ).
$.ajax({
type: "GET",
url: defaults.file,
dataType: "xml",
success: function(xml) {
$(xml).find('text').each(function() {
var textId = $(this).attr("id");
var text = $(this).find(defaults.lang).text();
aTexts[textId] = text;
});
$.each($("*"), function(i, item){
//alert($(item).attr("data-langtag"));
if($(item).attr("data-langtag") != null)
$(item).fadeOut(150).fadeIn(150).text(aTexts[$(item).attr("data-langtag")]);
});
}
});
It works fine having two clickable elements in the page where to choose english or french.
But it works just using simple text in XML.
I even tried this helper … https://github.com/kamranayub/jQuery-XML-Helper but no way, it doesn’t work here.
Have you any idea about to solve this ?
Tx a lot
Without actually trying this out, I suspect your problem is that you’re using jQuery’s
text()method to set HTML, so it’s escaping the angle brackets. Try: