我正在使用xml解析器NSXMLParser
来解析asn xml,并在url
中返回一些NSMutableArray
。除了french é
这一事实外,一切都很好被\U00e9
替换。
这是我的代码:
- (void)parseXMLFileAtURL:(NSString *)URL
{
NSURL *xmlURL = [NSURL URLWithString:URL];
xmlParser = [NSXMLParser alloc] initWithContentsOfURL:xmlURL];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[xmlParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser parse];
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"catalogue"]) {
// clear out our story item caches...
currentCatalogue = [[Catalogue alloc] init];
}
if ([elementName isEqualToString:@"partenaire"]) {
// clear out our story item caches...
currentPartenaire = [[Partenaire alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"catalogue"]) {
// Add currentCatalogue to array
[catalogueList addObject: currentCatalogue];
NSString *urls=[catalogueList valueForKey:@"url"];
NSLog(@"Current catalogue: urls=%@", urls);
}
if ([elementName isEqualToString:@"partenaire"]) {
// Add currentPartenaire to array
[partenaireList addObject: currentPartenaire];
/*NSLog(@"Current partenaire: raison_sociale=%@, lat=%@, lng=%@", currentPartenaire.raison_sociale, currentPartenaire.lat, currentPartenaire.lng);*/
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
// Catalogue setup
if ([currentElement isEqualToString:@"id_model"])
currentCatalogue.id_model = string;
if ([currentElement isEqualToString:@"url"])
{
if (currentCatalogue.url)
{
currentCatalogue.url = [NSString stringWithFormat: @"%@%@", currentCatalogue.url, string];
// NSLog(@"Valoare url in data handler %@", currentCatalogue.url);
}
else
currentCatalogue.url = string;
}
}
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
测试代码:100%工作
NSString* inputString =[NSString stringWithFormat:@"\40_TTRS_Coup\u00e9_TTRS_Roadster_Tarifs_20110428.pdf"];
NSLog(@"inputString is: %@ \n\n",inputString);
<强>输出:强>
inputString is: _TTRS_Coupé_TTRS_Roadster_Tarifs_20110428.pdf
答案 1 :(得分:0)
假设您的XML具有明确的编码,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
然后你应该首先解决2个问题。这些可能会或可能不会解决您的直接问题,但如果不是,它们将更容易缩小您所看到的问题。以下是您应该解决的问题:
尝试使用这些修复程序,看看它是否有效。如果没有,请使用更正的代码版本更新您的帖子,问题可能更明显。