当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - NSXMLParser works fine in iOS5 but not working in iOS6

问题描述:

In my iOS application, i m trying to parse the below xml using NSXMLParser. I can successfully parse this xml in iOS5 but in iOS6 the parser not getting into parserdidStartElement . In iOS6 parserDidStartDocument is successfully called but not getting into any other parser delegate methods.. Is there any problem with the xml format?? How can I fix this..

 <RESULTS>

<ROW>

<COLUMN NAME="NAME">Test1</COLUMN>

<COLUMN NAME="ANAME">testing xml1</COLUMN>

<COLUMN NAME="PHONE">4470111</COLUMN>

<COLUMN NAME="REMARKS"/>

<COLUMN NAME="XCOORD_DMS">227901.58873387</COLUMN>

<COLUMN NAME="YCOORD_DMS">391872.68493206</COLUMN>

<COLUMN NAME="XCOORD_WGS">51.49367618</COLUMN>

<COLUMN NAME="YCOORD_WGS">25.27912682</COLUMN>

</ROW>

<ROW>

<COLUMN NAME="NAME">Test2</COLUMN>

<COLUMN NAME="ANAME">testing xml2</COLUMN>

<COLUMN NAME="PHONE">4258444</COLUMN>

<COLUMN NAME="REMARKS"/>

<COLUMN NAME="XCOORD_DMS">229608.71442946</COLUMN>

<COLUMN NAME="YCOORD_DMS">386848.18818915</COLUMN>

<COLUMN NAME="XCOORD_WGS">51.51051535</COLUMN>

<COLUMN NAME="YCOORD_WGS">25.23373805</COLUMN>

</ROW>

</RESULTS>

This is the code..

- (void) initView:(JsonObject *) pageMenu{

appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSURL* url = [NSURL URLWithString:@"http://www.test.in/test.xml"];

NSXMLParser* parser = [[NSXMLParser alloc] initWithContentsOfURL:url];

[parser setDelegate:self];

[parser parse];

[parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName

namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString *)qName

attributes:(NSDictionary *)attributeDict{

NSLog (@"I have started");

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName

namespaceURI:(NSString *)namespaceURI

qualifiedName:(NSString *)qName{

NSLog (@"I have started");

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

NSLog (@"I have started");

}

-(void) parserDidStartDocument:(NSXMLParser *)parser {

NSLog (@"I have started");

}

-(void) parserDidEndDocument: (NSXMLParser *)parser {

NSLog (@"I have started");

}

网友答案:

I found what is the problem with XML... When creating the XML it should be saved as UTF-8 without BOM.. this is the problem. After doing this issue is fixed

网友答案:

Try this method (part of the delegate methods)

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
    NSLog(@"Error = %@", parseError);
}

I got an error on iOS 6 but not on iOS 5, but got an error message with that, where it says there is something wrong with the parsing. (Error Domain=NSXMLParserErrorDomain Code=9 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 9.)").

You can btw check error codes here : http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

Im Still trying to figure out my own problem, but this line may help you in the right direction.

Hope you solve it!

分享给朋友:
您可能感兴趣的文章:
随机阅读: