0

I load XML response from a server and parsed using NSXMLParser. No error in the simulator. But shows NSXMLParserErrorDomain Code=5 in iPhone.

NSString *settings = "http://website.com/settings";
NSURL *url = [NSURL  URLWithString:settings];
NSXMLParser *xmlParser = [[NSXMLParser alloc]  initWithContentsOfURL:url];
xmlParser.delegate = self;
BOOL success = [xmlParser parse];
if(success)
{
    NSLog(@"Parse Success");
}else{
    NSLog(@"Parse Failure");
    NSLog(@"Parse Error: %@",[xmlParser parserError]);
}

XML Response

<?xml version="1.0" encoding="utf-8"?>
<Settings>
  <AutoRefereshTime>10</AutoRefereshTime>
  <CashierPasswordRequired>Y</CashierPasswordRequired>
  <CheckoutTableColor>#FFFF00</CheckoutTableColor>
  <CompanyLogo>http://website.com/UCS_WS/Images/Logo/Logo.png</CompanyLogo>
  <CompanyName>UnoRestaurant</CompanyName>
  <ConfirmedTableColor>008ED5</ConfirmedTableColor>
  <Description>The Great Indian Restaurant</Description>
  <DevelopedBy>Unipro</DevelopedBy>
  <HoldTableColor>A02325</HoldTableColor>
  <ImageURL>http://rwebsite.com/UCS_WS/Images/Dish/</ImageURL>
  <isCategoryEnabled>Y</isCategoryEnabled>
  <isOtherLanguageEnabled>Y</isOtherLanguageEnabled>
  <NormalTableColor>#0000FF</NormalTableColor>
  <OrderScreenView>POS View</OrderScreenView>
  <OtherLanguage>Tamil</OtherLanguage>
  <SharedTableColor>#00FFFF</SharedTableColor>
</Settings>

Parse Error:

Error Domain=NSXMLParserErrorDomain Code=5 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)"
Master Stroke
  • 5,108
  • 2
  • 26
  • 57
partikles
  • 331
  • 3
  • 13
  • Most likely a problem with your inbound xml, probably an unbalanced block somewhere - can you post the xml? – Woodstock Aug 14 '13 at 11:26
  • @JohnWoods I shared xml file https://docs.google.com/file/d/0B1jfEVVBBWQeSlhZMkhQQjN3cEk/edit?usp=sharing – partikles Aug 14 '13 at 11:52
  • 1
    I have tested this with Simulators,iPhone and iPad. It works fine in Simulators and iPad. But doesn't work in iPhone. I have no clue why it doesn't work only in iPhone. Then I realized that in my iPhone wifi settings, I set to HTTP Proxy to Manual to do some network testing using Charles Web Debugging. Solved - Device Wifi Settings HTTP Proxy is in Off. But don't know the technical reason behind it. – partikles Aug 14 '13 at 12:16

1 Answers1

0

Refer the answer given by @mobibob here==> What is the meaning of NSXMLParserErrorDomain error 5.?

According to Dave DeLong,

That means it's having issues parsing your file.

I think it may be the XSLT reference in the XML - as it points to the webserver. I will review and get back to this question with an improved answer.

It was the path of the file. My code wasn't even close to the right location -- and I was missing a trailing letter 's'. The error code definition implies a "premature end of file", which caused me to truncate my file without any success. I then went back to basics and iterated on the file system to look for my file.

I debugged by using the NSFileManager to iterate to my file and then verified that it was loadable with the contentsAtPath method. I was able to dump it with NSLog(). Once I was convinced that the file was well-formed and loaded in raw form, I made certain that my NSURL was constructed with the same syntax and methods. Then it loaded correctly. Now I can load either a network file "full-featured" content or a local "sample" content.

NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: NSHomeDirectory()];
NSString *something;
NSString *f;

while( something = [dirEnumerator nextObject] ) {
    f = [[[NSString alloc] initWithFormat: @"%@/%@", NSHomeDirectory(), something] autorelease];
    if( [f hasSuffix :@"two_cookies.xml"] ){
    NSData *nsData = (NSData*) [[NSFileManager defaultManager] contentsAtPath: f];
        NSLog(@"%@", nsData );
    }
}

Output

2009-10-22 00:47:40.147 MyApp[13843:20b]

Community
  • 1
  • 1
Master Stroke
  • 5,108
  • 2
  • 26
  • 57
  • I have tested this with Simulators,iPhone and iPad. It works fine in Simulators and iPad. But doesn't work in iPhone. I have no clue why it doesn't work only in iPhone. Then I realized that in my iPhone wifi settings, I set to HTTP Proxy to Manual to do some network testing using Charles Web Debugging. Reason - Device Wifi Settings HTTP Proxy is in Manual. Solved - Device Wifi Settings HTTP Proxy is in Off. But don't know the technical reason behind it. – partikles Aug 14 '13 at 12:18