Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Get XML node content as html

This probably such a newbie question but I'm stuck at parsing an RSS feed. I've created an index of stories from an RSS feed whose structure is such that each story's full html content is contained within the description tag.

...
<item>
   <title>ABC story</title>
   <description>
      <p>Yada yada</p><a href='blah'>link here</a>....
   </description>
   ...
</item>
...

The index is working fine, it shows the title, thumbnail and pubDate of each item in the feed. What I want to do next is to show the full content of a story in the next window when it is clicked. I am able to do this with

story = itemList.item(c).getElementsByTagName(&quot;description&quot;).item(0).text;

and pass the story variable to the webview
but the html tags are stripped, so everything is in one paragraph and without formatting. Obviously, I shouldn't be using the text property but I can't figure out how to do it and the Javascript codes I have tried seem to cause errors in Titanium.

Is there any way that I can get the html content of an xml node such as this? Thanks in advance for the help!

— asked August 24th 2010 by Fritz Divinagracia
  • html
  • parsing
  • string
  • to
  • xml
0 Comments

3 Answers

  • Accepted Answer

    If you are in control of the feed, you can encapsulate the html as a CDATA. You can get this via getElementsByTagName("description").item(0).text and pass it directly to webView.html. I tried this and it works.

    — answered February 22nd 2011 by Dirk Krause
    permalink
    0 Comments
  • If you have a link to the HTML file remotely, you might fire a separate XHR request to fetch the HTML and inject it into a web view. Or you could just point the web view to an external URL.

    — answered August 24th 2010 by Kevin Whinnery
    permalink
    0 Comments
  • Your XML file is not correct.

    In the HTML part, you should replace < and > with &lt; and &gt; like this :

    ...
    <item>
       <title>ABC story</title>
       <description>
          <p>Yada yada</p><a href=&#39;blah&#39;>link here</a>....
       </description>
       ...
    </item>
    ...
    

    And in some case you need to use &amp; instead of &, &quot; instead of " and &#39; instead of '

    — answered October 1st 2010 by Pascal PLUCHON
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.