Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Objective c 如何解析XML字符串中的第一个属性?_Objective C_Xml_Ios7 - Fatal编程技术网

Objective c 如何解析XML字符串中的第一个属性?

Objective c 如何解析XML字符串中的第一个属性?,objective-c,xml,ios7,Objective C,Xml,Ios7,你能帮我完成这个程序吗?我正在解析一个xml文件,我的xml看起来像: 这是我的XML <pre> <site> <restaurant capacite="450" heure_debut_service="11:30:00" heure_fin_service="14:00:00" nom="LE MARCHE"> <disponibilite> <d i="haute" o="0" t="0"/&

你能帮我完成这个程序吗?我正在解析一个xml文件,我的xml看起来像: 这是我的XML

<pre>
<site>
<restaurant capacite="450" heure_debut_service="11:30:00" heure_fin_service="14:00:00" nom="LE MARCHE">
        <disponibilite>
            <d i="haute" o="0" t="0"/>
            <d i="haute" o="-17" t="10"/>
            <d i="haute" o="-13" t="20"/>
            <d i="haute" o="42" t="30"/>
            <d i="haute" o="109" t="40"/>
            <d i="haute" o="222" t="50"/>
            <d i="complet" o="298" t="60"/>
            <d i="complet" o="323" t="70"/>
            <d i="complet" o="315" t="80"/>
            <d i="complet" o="302" t="90"/>
            <d i="faible" o="285" t="100"/>
            <d i="faible" o="255" t="110"/>
            <d i="haute" o="213" t="120"/>
            <d i="haute" o="152" t="130"/>
            <d i="haute" o="96" t="140"/>
            <d i="haute" o="49" t="150"/>
        </disponibilite>
        <fluidite>
            <f i="fluide" o="0" t="0"/> // I want to search this value i="fluide"
            <f i="fluide" o="13" t="10"/>
            <f i="fluide" o="25" t="20"/>
            <f i="fluide" o="35" t="30"/>
            <f i="fluide" o="84" t="40"/>
            <f i="fluide" o="80" t="50"/>
            <f i="fluide" o="67" t="60"/>
            <f i="fluide" o="66" t="70"/>
            <f i="fluide" o="61" t="80"/>
            <f i="fluide" o="56" t="90"/>
            <f i="fluide" o="48" t="100"/>
            <f i="fluide" o="34" t="110"/>
            <f i="fluide" o="20" t="120"/>
            <f i="fluide" o="13" t="130"/>
            <f i="fluide" o="9" t="140"/>
            <f i="12" o="3" t="150"/>
        </fluidite>
        <stand nom="PIZZA PASTA ETC.">
            <fluidite>
                <f i="pertubé" t="0"/>
                <f i="fluide" t="10"/>
                <f i="fluide" t="20"/>
                <f i="fluide" t="30"/>
                <f i="ralenti" t="40"/>
                <f i="ralenti" t="50"/>
                <f i="fluide" t="60"/>
                <f i="ralenti" t="70"/>
                <f i="fluide" t="80"/>
                <f i="fluide" t="90"/>
                <f i="fluide" t="100"/>
                <f i="fluide" t="110"/>
                <f i="fluide" t="120"/>
                <f i="fluide" t="130"/>
                <f i="fluide" t="140"/>
                <f i="ralenti" t="150"/>
            </fluidite>
            <menuSemaine>
                <menu jour="0">
                    <plat>
                        Kebab   Sauce yaourt
                    </plat>
                </menu>
            </menuSemaine>
        </stand>
        <stand nom="COCOTTES">
            <fluidite>
                <f i="fluide" t="0"/> //My code search this value "i=fluide"
                <f i="fluide" t="10"/>
                <f i="fluide" t="20"/>
                <f i="fluide" t="30"/>
                <f i="ralenti" t="40"/>
                <f i="ralenti" t="50"/>
                <f i="fluide" t="60"/>
                <f i="ralenti" t="70"/>
                <f i="fluide" t="80"/>
                <f i="fluide" t="90"/>
                <f i="fluide" t="100"/>
                <f i="fluide" t="110"/>
                <f i="fluide" t="120"/>
                <f i="fluide" t="130"/>
                <f i="fluide" t="140"/>
                <f i="fluide" t="150"/>
            </fluidite>
            <menuSemaine>
                <menu jour="0">
                    <plat>
                        Escalope de dinde, crème forestière, macaronis
                    </plat>
                </menu>
            </menuSemaine>
        </stand>
</site>     
</pre>
我的解析器代码如下所示:

}

//流态 if[elementName IsequalString:@f] { self.aArticle.datePublished2=[attributeDict valueForKey:@t]; 如果[self.aArticle.datePublished2 IsequalString:@0] { self.aArticle.datePublished=[attributeDict valueForKey:@i]; } }

} 我的代码搜索此值i=fluide。 支架->标称=COCOTTES->流态->FI=fluide

但是我想要这个值 站->餐厅->流态->f->i=冲洗第一行 任何帮助都将不胜感激

谢谢

请查看GitHub上的课程,因为它将为您节省大量时间。我在许多不同的项目中使用它。您最感兴趣的方法是+NSDictionary*dictionaryWithXMLFile:NSString*path;和+NSDictionary*dictionaryWithXMLData:NSData*数据

最终将得到一个嵌套的NSDictionary对象,您可以使用标准的键/值操作或块来遍历该对象,如下所示


谢谢你的帮助。我是xcode的初学者。如何使用此代码。[dictionary EnumerateKeysandObjectsWithoOptions:NSEnumerationConcurrent usingBlock:^id key,id object,BOOL*stop{}];用我的函数你能举个例子吗?

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

    self.currentElement = elementName;

    if ([elementName isEqualToString:@"restaurant"]) {

    self.aArticle = [[Article alloc]init];
    self.aArticle.key = [NSString stringWithFormat:@"art%d",self.counter];
    self.counter++;
    
    [dictionary enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent
                              usingBlock:^(id key, id object, BOOL *stop) {
    
    }];