未使用NSXmlparser解析CData [英] CData not being parsed with NSXmlparser

查看:80
本文介绍了未使用NSXmlparser解析CData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务接收xml形式的响应,我使用nsxmlparser对其进行了解析。
在一个实例中,我收到了一个xml,其中两个标签中的内容相同。(与xml下面的内容重复)

I receive response in the form of xml from a service,which i parse using nsxmlparser. In an instance i received an xml where the content is same in two tags.(duplicate item as in below xml)

收到Xml:

<UserGeneratedContentItem>
    <link
      rel="details"
      uri="http://api.test.no/test.Ugc/vivo/usergeneratedcontentitem/16046" />
    <Data><![CDATA[<Type>Note</Type><Description>**6000 characters**</Description><Page>6</Page><ChapterNumber>1</ChapterNumber><ChapterTitle>Etikk og filosofi</ChapterTitle><Uri>http://api.test.no/test.Ugc/vivo/usergeneratedcontentitem/6</Uri><Data><StickyNotes><StickyNote name="icon_2" X="215.8" Y="352.7" note="**6000 characters**" dateTime="null" popupX="940" popupY="119" popupWidth="300" popupHeight="180" formatedDate ="2012-12-28-18-20-47" iconImage="1003"/></StickyNotes></Data>]]></Data>
  </UserGeneratedContentItem>
  <UserGeneratedContentItem>
    <link
      rel="details"
      uri="http://api.test.no/test.Ugc/vivo/usergeneratedcontentitem/16046" />
    <Data><![CDATA[<Type>Note</Type><Description>**6000 characters**</Description><Page>6</Page><ChapterNumber>1</ChapterNumber><ChapterTitle>Etikk og filosofi</ChapterTitle><Uri>http://api.test.no/test.Ugc/vivo/usergeneratedcontentitem/6</Uri><Data><StickyNotes><StickyNote name="icon_2" X="215.8" Y="352.7" note="**6000 characters**" dateTime="null" popupX="940" popupY="119" popupWidth="300" popupHeight="180" formatedDate ="2012-12-28-18-20-47" iconImage="1003"/></StickyNotes></Data>]]></Data>
  </UserGeneratedContentItem>

6000个字符包括字母,算术&

6000 characters include alphabet,arithmatic & general punctuation marks which would be encoded.

问题:

在-(void)parser:(NSXMLParser * )解析器发现CDATA:(NSData *)CDATABlock
方法内容在两种情况下都不相同(两个标记)。在一个实例中它给了我所有6000个字符,而在另一个实例中它使我只有大约300个字符的文字。我确认的两种情况下的文字(6000个字符)都是相同的。

In -(void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock method content in CDATABlock variable is not same in both cases(two tags).in one instance it gives me all 6000 characters and in the other instance it gives me only few may be around 300 characters.The text (6000 characters) is same in both cases which i confirmed.

这可能是什么原因?可以像我这样早些遇到此类问题的人来帮助我。

What could be the reason? Can someone help me may be anybody who faced such issue earlier like me.

Tnx提前。请让我知道是否有不清楚或不明白的事情。

Tnx in advance.Plz let me know if something is not clear or not understood.

推荐答案

这就是cdata的目的-不应该对其进行解析

thats what cdata is for -- it shouldnt be parsed

CDATA-(未解析的)字符数据

src: http://www.w3schools.com/xml/xml_cdata.asp

应解析PCDATA

您必须保存NSData块(可能被称为N次,因此必须合并该内容),然后-在您的情况下-然后解析结果作为单独的XML

you gotta save the block of NSData (may be called N times, so you have to concat that stuff) and -in your case- then parse the result as separate XML

这篇关于未使用NSXmlparser解析CData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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