NSString *xmlString = @"Jack13";如 何對這個xmlString構造一個NSXML,以及如何解析構造的NSXML.
解決方法:先轉換成NSData,然後用NSXMlParser進行解析。代碼:
- - (void)handleXMLData {
- NSString *myString = @"DoeJohn";
- NSData *myRequestData = [ NSData dataWithBytes: [myString UTF8String] length:[myString length]];
- NSXMLParser *myParser = [[NSXMLParser alloc] initWithData:myRequestData];
- [myParser setDelegate:self];
- [myParser setShouldProcessNamespaces:YES];
- [myParser setShouldReportNamespacePrefixes:YES];
- [myParser setShouldResolveExternalEntities:NO];
- BOOL success = [myParser parse];
- [myParser release];