显示xml页面的内容 [英] Displaying the contents of the xml page

查看:86
本文介绍了显示xml页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手.我想解析一个xml页面.源代码包含一些htmls标签.此html标签显示在我的模拟器中.我想过滤标签并仅显示内容.的XML就像

I am new to iphone development.I want to parse an xml page .The source code contains some htmls tags.This html tag is displayed in my simulator.I want to filter the tags and display only the content.The sorce code of xml is like

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

我希望显示自...起的一周内",而不是html标签.请帮帮我.谢谢

I want "in the week since an ..." to be displayed and not the html tags.Please help me out.Thanks

推荐答案

如在其他答案中之前所述,您xml中的数据位于CDATA块中-这意味着当您获取标记的内容时,XML解析器将无法为您摆脱按:"位-就其而言,全都是文本.

As said before in other answers, the data in your xml is inside a CDATA block - this means that when you get the contents of the tag, the XML parser won't be able to get rid of the 'By:' bit for you - as far as it's concerned, it's all just text.

但是,如果要在UIWebView(而不是UILabel等)中以HTML的形式将其显示在内部,则可以在字符串的开头添加样式表,以使"By:"隐藏.像

However,if you're going to display it inside as HTML inside a UIWebView (instead of a UILabel etc), you can add a style sheet to the start of the string that makes the 'By:' hidden. Something like

NSString *cssString = @"<style type='text/css'>span.by { display:none; }</style>"
NSString *html = [NSString stringWithFormat:@"<html><head>%@</head><body>%@</body></html>", cssString, descriptionString];
[webView loadHTMLString:html baseURL:nil];

其中descriptionString是xml中<description>标记的内容.

where descriptionString is the contents of the <description> tag in your xml.

但是这种方法有点繁琐,我会非常努力地从您的服务器中获取一些更干净的xml!

However this approach is a little heavy handed, I would try very hard to get some cleaner xml from your server!

至于实际解析xml,请尝试 NSXMLParser 对象.

As for actually parsing the xml, try the NSXMLParser object.

这篇关于显示xml页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆