How to handle the CDATA tag while parsing an XML file in iPad

坚强是说给别人听的谎言 提交于 2019-12-10 09:52:48

问题


I am working on an application where I need to parse some XML files that consists CDATA tags. Parsing ordinary xml is quite straight forward but I am facing problems to retrieve data that is inside the CDATA tag.

The parser:foundCDATA: method is being called for each CDATA tag encountered where the parameter CDATABlock is of NSData type.

Please suggest a way to parse the CDATA tag.


回答1:


If you need to extract the string from CDATA, you could use this block in foundCDATA:

NSMutableString *lStr = [[NSMutableString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];



回答2:


i have taken string from the CDATA tag as Oleg Danu said but still it consists XML tags.So i wrote that entire string to a file,whenever CDATA found, and created one more XMLParser by setting the delegate to same class as that of original Parser.All tags in CDATA tag are parsed properly by the secondary parser.The parser will be released at the end of the foundCDATA method and actual parsing continues as it is.



来源:https://stackoverflow.com/questions/4816422/how-to-handle-the-cdata-tag-while-parsing-an-xml-file-in-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!