在C语言中读取CDATA节以解析XML

在C语言中读取CDATA节以解析XML

本文介绍了在C语言中读取CDATA节以解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究有关解析google weather api的示例iPhone教程,该api似乎已不存在,因此我已经找到了一个替代方案.本教程使用libxml2和xpath查询来解析xml文件.我成功地解析了大多数数据.我的问题是天气符号的图标URL包含在CDATA部分中:

Im working through an example iphone tutorial on parsing the google weather api, The api seems to no longer exist so I have sourced an alternative. The tutorial uses libxml2 and xpath query to parse the xml file. I am succesfully parsing most of the data. The problem I have is that the icons url for the weather symbols are enclosed in CDATA sections:

 <weatherIconUrl><![CDATA[http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0010_heavy_rain_showers.png]]></weatherIconUrl>

我了解xpath无法读取CDATA中包含的项目.反正从标记中提取此数据吗?

I understand that xpath cannot read items enclosed in CDATA . Is anyway of pulling this data from within the tags?

推荐答案

使用parser:foundCDATA:

- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock

解析CDATA.

https://developer.apple.com/documentation/foundation/nsxmlparserdelegate /1407687-解析器

这篇关于在C语言中读取CDATA节以解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:30