开发者

Ignore CDATA while xml parsing

开发者 https://www.devze.com 2022-12-17 06:20 出处:网络
I am new to iphone development.I want to ignore CDATA tag wh开发者_运维百科ile parsing because it consider the HTML tag following it as text.Since i want to display the content alone ,i want my parser

I am new to iphone development.I want to ignore CDATA tag wh开发者_运维百科ile 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消