开发者

Parse an XML stored in NSData with libxml2

please can you help me using libxml2 to parse an XML stored in a NSMutableData object? I get the XML using

NSString *path = "http://www.mySite.com/XMLPATH.xml";

NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:path] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

and

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data_
    { 
        [data appendData:data_];
    }

where data is an instance of NSMutableData.

Now how can i start the libxml2 to parse this data? I need the equivalent of

NSString *xml; // string containing XML
    mlDocPtr doc = xmlParseMemory([xml UTF8String], [xml lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);

where xml is my NSMutabledata and not a NSString.

Thanks!

EDIT:

I'm currently using NSXMLParser to do the job, but i'd like to have a parser that automatically parses all the XML, with its node structure. With NSXMLParser i need to man开发者_开发技巧ually set the node structure of my XML


Any reason you are not using the NSXMLParser. It is a nice wrapper written by Apple and included on all iOS versions.

http://developer.apple.com/library/mac/ipad/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜