NSXMLParser 缺少字符
我正在使用 NSXMLParser 分析 XML 文件,它效果很好,但有时会给出不准确的结果。
例如,我得到这个 URL:
http://www.thehungersite.com/clickToGive/home.faces;jsessionid=01F974DC9E276DA587AE299175EDF4F4.ctgProd02?siteId=4&link=ctg_trs_home_from_ths_home_sitenav
但是 NSXMLParser
输出:
http://www.thehungersite.com/clickToGive/home.faces;jsessionid=01F974DC9E276DA587AE299175EDF4F4.ctgProd02?siteId=4&link=ctg_trs_home_from_ths_home_sitenav
由于某种原因,它忽略了 #38;< /code> 字符串的一部分 -我怎样才能取回这个?假设这是 HTML 编码,我尝试过
stringByAddingPercentEscapesUsingEncoding:
但这不起作用。
有什么想法吗?
I am analyzing an XML file using NSXMLParser
, which works great but sometimes gives me inaccurate results.
For example, I get this URL:
http://www.thehungersite.com/clickToGive/home.faces;jsessionid=01F974DC9E276DA587AE299175EDF4F4.ctgProd02?siteId=4&link=ctg_trs_home_from_ths_home_sitenav
but NSXMLParser
outputs:
http://www.thehungersite.com/clickToGive/home.faces;jsessionid=01F974DC9E276DA587AE299175EDF4F4.ctgProd02?siteId=4&link=ctg_trs_home_from_ths_home_sitenav
For some reason, it ignored the #38;
part of the string - how can I get this back? Assuming this was HTML encoding I have tried stringByAddingPercentEscapesUsingEncoding:
but that will not work.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
XML 使用与 HTML 相同的字符引用编码机制(尽管它只有 5 个预定义的命名实体,而不是为 HTML 定义的大量实体)。
&
是&
字符的编码。XML uses the same character reference encoding mechanism as HTML (although it has only 5 predefined named entities, as opposed to the huge number defined for HTML).
&
is an encoding for the&
character.也许这个问题的最佳答案可能会有所帮助:
Objective-C:如何替换 HTML 实体?
它基本上是某人创建的 NSString 类别,提供 NSString 中 HTML 实体的编码和解码。
Perhaps the top answer to this question might help:
Objective-C: How to replace HTML entities?
It's basically a category to NSString someone made that offers both encoding and decoding of HTML entities in NSString.
您正在使用 ISO 标准。尝试使用 %26 或使用 url 编码。
You're using the ISO standard. Try either using %26 or by using url encoding.