开发者

iphoneSDK and NSXMLParser problem

So have an XML file it parses perfectly fine up until I get a to an element that has weird tag inside of it. The xml file looks a little like this.

<xml>
   <badtag><![CDATA[ This is the text that i want ]]> </badtag>
</xml>

For some reason when it comes in contact with "that*" tag the app goes hay wire. The next view loads however it does not perform any of the proper actions after that. Basically it loads a blank table view because it never calls to the "cellForRowAtIndexPath" (or any other essential table methods).

I have absolutly no explanation for this. If i remove that tag I can get it to load parse the XML file perfectly.

Is their anyway i can search the entire XML file and remove all instances of "<[CDATA[" and "]]>" at runtime.

HUGE EDIT:

I am just now noticing if i type

< ! C D A T A (whatever text is i开发者_运维技巧n here disappears) ] ] >

Here it blocks out all the text aswell.


'<' '&' and '>' are HTML Reserved characters as well as a few others, They need to be escaped for it to pass correctly or it will produce an error. Valid XML should have these characters already escaped so it should be fixed on the server end.

If you are using NSXMLParser and you try and run invalid input through it like what you have above it will produce an error and stop passing the contents of the XML.

If you don't have access to the source XML leave a comment and I'll see if I can find some ways people have fixed it.


- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
    NSString *someString = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜