char* buffer = [html UTF8String]; htmlDocPtr doc = htmlReadMemory(buffer, (int)html.length, "", "UTF-8", 0); xmlNodePtr root = xmlDocGetRootElement(doc); NSMutableString* mutableString = [NSMutableString stringWithString:@"<document><head><style> .topLeftLogo { tv- position: top-left; color:rgb(255,255,255); tv-text-style: headline; }</style></head><divTemplate>"]; [mutableString appendFormat:@"%@</divTemplate></document>", [self parseTag:root]]; return mutableString; } - (NSString *)parseTag: (htmlNodePtr)ptr { NSMutableString* mutableString = [NSMutableString string]; for (htmlNodePtr node = ptr; node != NULL; node = node->next) { switch (node->type) { case XML_ELEMENT_NODE: if(node->children != NULL) { NSString* ret = [self parseTag:node->children]; [mutableString appendString:ret]; } break; case XML_TEXT_NODE: if (node->content != NULL) { NSString* content = [[NSString stringWithUTF8String:(char *)node->content] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if (content.length != 0) { [mutableString appendFormat:@"<text class=\"topLeftLogo\">%@</text>", content]; } } default: break; } } return mutableString; } MJCYNM)5.-QBSTFSΛͬͨ57.-ม