编辑:
哦,@Ankit Srivastava 的答案是正确的。我没有发现这是一个 CDATA 块。按照他的回答,但我不会删除我的,因为这对你仍然有用。
您应该实现 NSXMLParser 委托。在你的 .h 文件<NSXMLParserDelegate>
中然后你必须在你的 m 文件中放入 3 个有用的方法。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (element == nil) // where element is a NSMutableString
element = [[NSMutableString alloc] init];
[element appendString:string];
}
这并不重要,否则它总是会调用didStart end didEnd。现在我们有 ex: :
elementName //contains your tag name. In this case "mytag"
element // contains text beetween tags. In this case null. But in <mytag>something</mytag> element = something.
attributeDict //This is probably most important to you. That contains NSDictionary with all your parameters. In above example this is a dictionary with key: myparam and object: test