Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在iphone中使用libxml2解析xml_Ios_Libxml2_Nsxml - Fatal编程技术网

Ios 如何在iphone中使用libxml2解析xml

Ios 如何在iphone中使用libxml2解析xml,ios,libxml2,nsxml,Ios,Libxml2,Nsxml,我正在以xml的形式从.NETWeb服务器获取信息 我正在使用NSXml解析器来解析它 但解析需要时间 我听说libxml2比NSXml解析器更快 但是我没有找到关于如何使用它的明确信息 任何人都可以发布关于如何使用libxml2解析的示例代码或示例 提前谢谢你。我建议你看看 它很快,因为它使用libxml2,而且比直接使用libxml2简单得多,后者是用普通c编写的。您需要使用XML解析来实现这一点。我建议使用touchXML。下面是一个示例代码: -(void)callwebservice{

我正在以xml的形式从.NETWeb服务器获取信息

我正在使用NSXml解析器来解析它

但解析需要时间

我听说libxml2比NSXml解析器更快

但是我没有找到关于如何使用它的明确信息

任何人都可以发布关于如何使用libxml2解析的示例代码或示例


提前谢谢你。

我建议你看看


它很快,因为它使用libxml2,而且比直接使用libxml2简单得多,后者是用普通c编写的。

您需要使用XML解析来实现这一点。我建议使用touchXML。下面是一个示例代码:

-(void)callwebservice{
    NSString *path = @"YOUR URL";
    [self grabRSSFeed:path];
}

-(void) grabRSSFeed:(NSString *)blogAddress {
    // Initialize the blogEntries MutableArray that we declared in the header
    blogEntries = [[NSMutableArray alloc] init];    

    // Convert the supplied URL string into a usable URL object
    NSURL *url = [NSURL URLWithString: blogAddress];

    // Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the object that actually grabs and processes the RSS data
    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];

    // Create a new Array object to be used with the looping of the results from the rssParser
    NSArray *resultNodes = NULL;

    // Set the resultNodes Array to contain an object for every instance of an  node in our RSS feed
    resultNodes = [rssParser nodesForXPath:@"//Node you want to parse" error:nil];

    // Loop through the resultNodes to access each items actual data
    for (CXMLElement *resultElement in resultNodes) {
        // Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
        NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];

        // Create a counter variable as type "int"
        int counter;

        // Loop through the children of the current  node
        for(counter = 0; counter < [resultElement childCount]; counter++) {
            // Add each field to the blogItem Dictionary with the node name as key and node value as the value
            [blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
            NSLog(@"Data = %@",[[resultElement childAtIndex:counter] stringValue]); 
        }

        // Add the blogItem to the global blogEntries Array so that the view can access it.
        [blogEntries addObject:[blogItem copy]];

    }

    [YourTable reloadData];
}
-(void)callwebservice{
NSString*path=@“您的URL”;
[自抓取种子:路径];
}
-(void)grabsfeed:(NSString*)博客地址{
//初始化我们在标头中声明的blogEntries MutableArray
blogEntries=[[NSMutableArray alloc]init];
//将提供的URL字符串转换为可用的URL对象
NSURL*url=[NSURL URLWithString:blogAddress];
//基于TouchXML“CXMLDocument”类创建一个新的rssParser对象,这是实际获取和处理RSS数据的对象
CXMLDocument*rssParser=[[CXMLDocument alloc]initWithContentsOfURL:url选项:0错误:nil]autorelease];
//创建一个新的数组对象,用于rssParser结果的循环
NSArray*resultNodes=NULL;
//将resultNodes数组设置为包含RSS提要中每个节点实例的对象
resultNodes=[rssParser nodesForXPath:@”//要分析的节点“error:nil];
//循环遍历resultNodes以访问每个项目的实际数据
对于(resultNodes中的CXMLElement*resultElement){
//创建一个临时的MutableDictionary来存储其中的items字段,它最终将在blogEntries中结束
NSMutableDictionary*blogItem=[[NSMutableDictionary alloc]init];
//创建类型为“int”的计数器变量
整数计数器;
//循环遍历当前节点的子节点
用于(计数器=0;计数器<[resultElement childCount];计数器++){
//将每个字段添加到blogItem字典中,节点名称作为键,节点值作为值
[blogItem setObject:[[resultElement childAtIndex:counter]stringValue]forKey:[[resultElement childAtIndex:counter]名称]];
NSLog(@“Data=%@,[[resultElement childAtIndex:counter]stringValue]);
}
//将blogItem添加到全局blogEntries数组中,以便视图可以访问它。
[blogEntries addObject:[blogItem copy]];
}
[您的表重新加载数据];
}

导入头文件中的touchXML库。

我需要使用soap操作和xml字符串来传递我如何将其传递给此url您需要生成一个url,从中解析服务器中的数据。