When creating the new div, you're setting the "text" property. In MooTools,
everything set to "text" will be escaped. You like want to set it o "html".
var newsItem = new Element('div', {
'id' : 'newsItem' + i,
'html' :
nodes[i].getElementsByTagName("value")
[0].childNodes[0].nodeValue
});
On Fri, Oct 15, 2010 at 12:30 PM, dawnj2sb <[email protected]>wrote:
> I am trying to create a news feed using an AJAX request of an XML
> file. I finally got the request to work, but am unable to get HREFs
> within the XML node values to render as actual links in the page.
>
> This is the function I'm using:
>
> var feedUrl = 'corpNewsFeed.xml';
> var request = new Request({url:feedUrl, method:'get',
> onSuccess : function(data, xml){
> nodes =
> xml.documentElement.getElementsByTagName("newsItem");
> if (nodes.length > 0) {
> for (i = 0; i < nodes.length; i++) {
> var newsItem = new Element('div', {
> 'id' : 'newsItem' + i,
> 'text' :
> nodes[i].getElementsByTagName("value")
> [0].childNodes[0].nodeValue
> });
> newsItem.inject($('newsContainer'));
> };
> } else{alert("There are no news items today.");}
> },
> onFailure: function(error){alert("Error: " + error);}
> }).send();
>
> And here are some news items:
>
> <newsCatalog>
> <newsItem>
> <id>item1</id>
> <value>We are proud to announce we have bought <a
> href="http://
> www.company.com" target="_blank">another company</a>.</value>
> </newsItem>
> <newsItem>
> <id>item2</id>
> <value>Profits are skyrocketing!</value>
> </newsItem>...
>
> If I leave the XML file the way you see it, then everything after "We
> are proud to announce we have bought..." doesn't render (although it
> is returned in the AJAX response). If I change the HREF code to be
> encoded:
>
> <value>We are proud to announce we have bought <a href="http://
> www.company.com" target="_blank">another company</
> a>.</value>
>
> Then it is rendered with the HREF code as part of the text and there
> is no link. How do I turn it into a link? Which version is correct and
> is it just a matter of attaching some MooTools charEncode function to
> the values?