Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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
NSXMLParser ios-如何解析子节点_Ios_Nsxmlparser - Fatal编程技术网

NSXMLParser ios-如何解析子节点

NSXMLParser ios-如何解析子节点,ios,nsxmlparser,Ios,Nsxmlparser,我有一个xml格式,下面是它的一部分 <a:IngredientItemIds xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> enter<b:int>206932</b:int><b:int>206930</b:int></a:IngredientItemIds><a:IsGiftCard>false</a:IsGi

我有一个xml格式,下面是它的一部分

<a:IngredientItemIds xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
enter<b:int>206932</b:int><b:int>206930</b:int></a:IngredientItemIds><a:IsGiftCard>false</a:IsGiftCard>

输入206932206930False
……等等

我的问题是XML解析器为元素“IngreditItemId”获取“none” 相反,我想要的是一个包含所有“int”标记的数组

我正在使用NSXML解析器foundcharacters、didstartElement和didEndElement的方法

有人知道如何在NSXMLparser中解析子节点吗


谢谢。

试试这个:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

        // If the current element name is equal to "a:IngredientItemId " then initialize the temporary dictionary.

        if ([elementName isEqualToString:@"a:IngredientItemIds"]) {
            self.dictTempDataStorage = [[NSMutableDictionary alloc]init];
        }

        // Keep the current element.
        self.currentElement = elementName;
    }

    -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

        if ([elementName isEqualToString:@"a:IngredientItemIds"]) {
           [self.arrNeighboursData addObject:[[NSDictionary alloc] initWithDictionary:self.dictTempDataStorage]];
        }
        else if ([elementName isEqualToString:@"b:int"]){
            // If the b:int element was found then store it.
            [self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:@"b:int"];
        }

        // Clear the mutable string.
        [self.foundValue setString:@""];
    }


    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
        // Store the found characters if only we're interested in the current element.
        if ([self.currentElement isEqualToString:@"b:int"] ) {

            if (![string isEqualToString:@"\n"]) {
                [self.foundValue appendString:string];
            }
        }
    }

您给定的xml中存在错误,请修复该错误。