无法从 XML 中正确解析字符串
我正在解析一个 XML 文件,其中的数据采用“葡萄牙语”语言。数据已成功解析,但未按预期返回数据, 示例=>我正在解析字符串“Próximo GP”,它返回我“óximo GP”。它正在修剪前两个字母。我在其他字符串中遇到同样的问题。
我应该怎么办。请帮忙。 谢谢-
I am parsing an XML file, ion which data is in "Portugese" language. data is getting parsed successfully but its not returnong the data as expected,
Example=> I am parsing string "Próximo GP" and it is returning me "óximo GP". Its is trimming the first two letters. same problem I am having in other strings.
What should I do. Please help.
Thanks-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设计使然。
NSXMLParser
不保证它会一次性传递元素的整个字符串内容。您应该声明一个可变字符串来存储找到的字符,并在多次调用parser:foundCharacters:
方法时附加到该字符串。看看Apple的示例代码,他们到处都是这样做的。This is by design.
NSXMLParser
does not guarantee that it will deliver the entire string contents of an element in one go. You are supposed to declare a mutable string to store the found characters in and append to this string when theparser:foundCharacters:
method is called multiple times. Look at Apple's sample code, they do it like this everywhere.