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
精彩评论