tags:

views:

465

answers:

2

I am new to iphone development.I want to ignore CDATA tag while parsing because it consider the HTML tag following it as text.Since i want to display the content alone ,i want my parser to ignore CDATA tag.My source code is

[CDATA[<br /><p class="author"><span class="by">By: </span>By Sydney Ember</p><br><p>In the week since an </p>]].

Is there any way to ignore CDATA tag? Is there any way to parse my source twice so it displays only the content?

Please give me some sample code.Please help me out.Thanks.

+3  A: 

If you treat the CDATA content as XML instead of CDATA then your parser will throw an error (since your HTML is a weird mix of XHTML and HTML and is not well formed).

If you want to get the HTML, then parse the XML, extract the text content of the node, then parse that text as HTML.

David Dorward
how to parse the text with html, please give some sample codes
Warrior
+1  A: 

There is no way to ignore the CDATA tag - it's part of the xml spec and parsers should honour it.

If you don't like the idea of this answer to your earlier question, you could get the contents of the CDATA section and parse it as XML again. However, this is highly not recommended! You don't know that the contents of the CDATA are going to be valid xml (they're probably not).

If you can 100% guarentee that the CDATA section contains the form you have above, you could probably use some string manipulation to get the data out (i.e. string replace '<span class="by">By: </span>' with '') but again, this will almost certainly break if the CDATA contents change.

Where is the xml coming from? It's a better idea to talk to owner of the service and get them to send you instead of description something like

<description>
  <author>By Sydney Ember</autho>
  <text>In the week since an </text>
</description>

S

deanWombourne
Even i can understand the flaw in the source code.But all are expecting only the output and not understanding the problem in source code which has CDATA.
Warrior