简体   繁体   中英

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

< ! CDATA (whatever text is in 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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM