Vickate_将.txt文件转成字符串String

Began

  • 不逼逼,直接代码
NSMutableString *str = [[NSMutableString alloc] init];
    NSString *protocolPath = [[NSBundle mainBundle] pathForResource:_textFiel ofType:@"txt"];
    xmlDocPtr doc = xmlReadFile([protocolPath UTF8String], NULL, XML_PARSE_RECOVER);
    if (!doc)
    {
        return nil;
    }
    xmlNodePtr root = xmlDocGetRootElement(doc);
    if (root)
    {
        for (xmlNodePtr curNode = root->children; NULL != curNode; curNode = curNode->next)
        {
            if(strcmp((char *)curNode->name, "string") == 0)
            {
                [str appendString:[NSString stringWithCString:(const char*)xmlNodeGetContent(curNode) encoding:NSUTF8StringEncoding]];
                [str appendString:@"\n"];
            }
        }
    }
    xmlFreeDoc(doc);
    return str;

End

你可能感兴趣的:(Vickate_将.txt文件转成字符串String)