Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PizzaTray

macrumors newbie
Original poster
Oct 31, 2009
25
0
Hey all i'm having this issue for a while,

I'm getting the xml string from the server after i send the soap msg.
Until now, all the xml results from the server was in 'utf-16' encoding, so i've
encoded the string xml result to 'utf-16' and then parse it.

this time i'm getting the xml in 'windows-1255' encoding, so i make this changes as u c right here:
Code:
NSMutableString *str = [[NSMutableString alloc]initWithString:[sharedState commonXML]];
str  = (NSMutableString*)[str stringByReplacingOccurrencesOfString:@"windows-1255" withString:@"iso-8859-1"];
		    NSData	*data = [str	dataUsingEncoding:CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingWindowsHebrew)];
xmlparser = [[SimpleXMLParser alloc] initWithData:data];
[xmlparser parse];
[xmlparser dumpRoot];
The problem here that after i Parse the encoded xml string,
the comparing of strings in my recursive doesn't work this time:
(notice the red code line)
Code:
- (void) dumpArrayRecursive: (NSArray*) inArray parentElement:(NSString*)inParent
{
	for (int i=0;i<[inArray count];i++)
	{
		NSDictionary* thisDict = [inArray objectAtIndex:i];

if[COLOR="Red"][B]([[thisDict objectForKey:@"element"]isEqualToString:@"Name"])[/B][/COLOR] {
				A *a = [arr_a lastObject];
				a.name = [thisDict objectForKey:@"data"];
			}
[self dumpArrayRecursive:[thisDict objectForKey:@"children"] parentElement:[thisDict objectForKey:@"element"] ];
	}
}
- (void) dumpRoot
{
	[self dumpArrayRecursive:theMainStack parentElement:@"Root"];
}

// Start of element
- (void)parser: (NSXMLParser *)parser
didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName
	attributes:(NSDictionary *)attributeDict
{
	if (!rootName)
		rootName = [NSString stringWithString:elementName];

	currentPropertyName = [NSString stringWithString:elementName];
	currentData = [NSMutableString string];
	[currentDataStack addObject:currentData];
		
	NSMutableDictionary* newDict = [[NSMutableDictionary alloc] initWithCapacity:3];
	[newDict setObject:[[NSMutableArray alloc] init] forKey:@"children"];
	[theMainStack addObject:newDict];
	//NSLog(@"Pushed: %@", elementName);
}

// Found Character
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string
{
	if (currentData) 
        [currentData appendString:string];
}

// End Element
- (void) parser:(NSXMLParser *)parser
  didEndElement:(NSString *)elementName
   namespaceURI:(NSString *)namespaceURI
  qualifiedName:(NSString *)qName
{
	NSMutableDictionary* nodeDict = [theMainStack lastObject];
	
	currentData = [currentDataStack lastObject];
	[currentDataStack removeLastObject];
			
	[nodeDict setObject:elementName forKey:@"element"];
	[nodeDict setObject:[currentData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:@"data"];
		
	// only pop/add up the tree if we aren't the root node
	if ( ![rootName isEqualToString:elementName] )
	{
		[theMainStack removeLastObject];
		//NSLog(@"Popped: %@", elementName);

		NSMutableDictionary* parentDict = [theMainStack lastObject];
		NSMutableArray* parentArray = [parentDict objectForKey:@"children"];
		[parentArray addObject:nodeDict];
	}
	currentData = nil;
}

When its all the same string (equal) and still its doesn't work,
and the compare are wrong.
is there any 'decoding' code i need to add?
or maybe other encoding?

Thx.

I really need your help here,
if someone have an idea or even some direction i'll be very happy to hear it.

I've got less then two weeks to finish this project in my job and i'm stuck.
:(

at this situation 'isEqualToString' or 'isEqual' always returns NO,
and if i'm using 'caseInsensitiveCompare' its always returns YES.

never happen to me before with 'isEqualToString'..
any ideas?

EDIT:

SUCCESS :D:D

if someone having the same issue,
here's the way to fix it :)
Code:
// instead of 'isEqualToString', use:
 if([someString compare:@"Name"] == NSOrderedSame) {
//Do Something.
}
 
What's the result when you log [thisDict objectForKey:mad:"element"] to the console? What does a standard (case-sensitive) compare: result in?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.