TouchXML:使用 Iphone 读取 EDSP 信息时出现问题

发布于 2024-10-01 03:31:39 字数 5623 浏览 4 评论 0原文

我正在使用 TouchXML 来解析传入的 XML 文件。到目前为止,一切工作正常,但对于这个文件,我遇到了很多麻烦:

<item>
        <title><![CDATA[Hotel Katschberghof]]></title>
        <edsp:uid>92090</edsp:uid>
        <link>http://test.dataapi.herold.at/search?aId=yasssu&amp;auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&amp;c=15&amp;provider=&amp;q=PN1VW&amp;type=yp_detail</link>
        <description><![CDATA[Betrieben wird ein 4 Sterne Hotel mit ca. 140 Betten.  Mit 29.04.2008 wurde die Einzelfirma Christine Kröth in die gegenständliche Einzelfirma eingebracht.]]></description>
        <guid>PN1VW</guid>
        <georss:point>47.0579478809204 13.6152591216261</georss:point>
        <geo:point>
            <geo:lat>47.0579478809204</geo:lat>
            <geo:long>13.6152591216261</geo:long>
        </geo:point>
        <edsp:itemExt type="ds">
            <edsp:fReq reqVStr="Details">
                <edsp:reqQStr>http://test.dataapi.herold.at/search?aId=yasssu&amp;auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&amp;c=15&amp;provider=&amp;q=PN1VW&amp;type=yp_detail
                </edsp:reqQStr>
            </edsp:fReq>
            <edsp:coord lat="47.0579478809204" long="13.6152591216261" />
            <edsp:contact>
                <edsp:cName fN="" lN="Hotel Katschberghof" />
                <edsp:cInfo>
                    <edsp:tel>+4347342660</edsp:tel>
                    <edsp:fax>+434734406</edsp:fax>
                    <edsp:eml>[email protected]</edsp:eml>
                    <edsp:web>http://www.katschberghof.at</edsp:web>
                </edsp:cInfo>
                <edsp:cAddr str="Nr. 4" pCd="9863" cty="Katschberghöhe"
                    cnt="A" />
            </edsp:contact>
        </edsp:itemExt>
        <edsp:itemInfo type="lst">
            <edsp:lstDetails>
                <edsp:actionProps>
                    <edsp:actionProp action="showMapLink" enabled="true" />
                    <edsp:actionProp action="showRouteLink" enabled="true" />
                    <edsp:actionProp action="showFacebookLink"
                        enabled="false" />
                    <edsp:actionProp action="showVideoLink" enabled="false" />
                    <edsp:actionProp action="showDiaLink" enabled="false" />
                    <edsp:actionProp action="showVoucherLink" enabled="false" />
                </edsp:actionProps>
            </edsp:lstDetails>
            <edsp:styleProps>
                <edsp:styleProp styleRef="mobEuro" />
            </edsp:styleProps>
        </edsp:itemInfo>
    </item>

所有相关信息(主要是:edsp:contact 和 geo:lat)

NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"testhotels.xml"];

NSData *XMLData   = [NSData dataWithContentsOfFile:XMLPath];

CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];

NSLog(@"Starting XML Parsing");

NSArray *nodes = NULL;

现在我尝试获取 //item,但没有获得(CXMLElement * 的 节点中的节点){

    item = [[NSMutableDictionary alloc] init];

    int counter;

    for(counter = 0; counter < [node childCount]; counter++) {

    //  [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];

        NSString * value = [[[node childAtIndex:counter] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        if ([value length] != 0){

            [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] localName]]; //localName]];

        }



    }

    [res addObject:item];

    NSLog(@"test 1: %@", [[item valueForKey:@"edsp"] stringValue]);

    [item release];

}

NSLog(@"%@", res);

[res release];

这是日志文件:

{
    description = "Betrieben wird ein 4 Sterne Hotel mit ca. 140 Betten.  Mit 29.04.2008 wurde die Einzelfirma Christine Kr\U00f6th in die gegenst\U00e4ndliche Einzelfirma eingebracht.";
    guid = PN1VW;
    itemExt = "\n\t\t\t\t\n\t\t\t\t\thttp://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t+4347342660\n\t\t\t\t\t\t+434734406\n\t\t\t\t\t\[email protected]\n\t\t\t\t\t\thttp://www.katschberghof.at\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t";
    link = "http://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail";
    point = "\n\t\t\t\t47.0579478809204\n\t\t\t\t13.6152591216261\n\t\t\t";
    title = "Hotel Katschberghof";
    uid = 92090;
}

感谢您提供如何解决此问题的任何建议...

BR,

Stefan

I am using TouchXML to parse incoming XML Files. Until now, everything worked fine, but with this file, I am having lots of troubles:

<item>
        <title><![CDATA[Hotel Katschberghof]]></title>
        <edsp:uid>92090</edsp:uid>
        <link>http://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail</link>
        <description><![CDATA[Betrieben wird ein 4 Sterne Hotel mit ca. 140 Betten.  Mit 29.04.2008 wurde die Einzelfirma Christine Kröth in die gegenständliche Einzelfirma eingebracht.]]></description>
        <guid>PN1VW</guid>
        <georss:point>47.0579478809204 13.6152591216261</georss:point>
        <geo:point>
            <geo:lat>47.0579478809204</geo:lat>
            <geo:long>13.6152591216261</geo:long>
        </geo:point>
        <edsp:itemExt type="ds">
            <edsp:fReq reqVStr="Details">
                <edsp:reqQStr>http://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail
                </edsp:reqQStr>
            </edsp:fReq>
            <edsp:coord lat="47.0579478809204" long="13.6152591216261" />
            <edsp:contact>
                <edsp:cName fN="" lN="Hotel Katschberghof" />
                <edsp:cInfo>
                    <edsp:tel>+4347342660</edsp:tel>
                    <edsp:fax>+434734406</edsp:fax>
                    <edsp:eml>[email protected]</edsp:eml>
                    <edsp:web>http://www.katschberghof.at</edsp:web>
                </edsp:cInfo>
                <edsp:cAddr str="Nr. 4" pCd="9863" cty="Katschberghöhe"
                    cnt="A" />
            </edsp:contact>
        </edsp:itemExt>
        <edsp:itemInfo type="lst">
            <edsp:lstDetails>
                <edsp:actionProps>
                    <edsp:actionProp action="showMapLink" enabled="true" />
                    <edsp:actionProp action="showRouteLink" enabled="true" />
                    <edsp:actionProp action="showFacebookLink"
                        enabled="false" />
                    <edsp:actionProp action="showVideoLink" enabled="false" />
                    <edsp:actionProp action="showDiaLink" enabled="false" />
                    <edsp:actionProp action="showVoucherLink" enabled="false" />
                </edsp:actionProps>
            </edsp:lstDetails>
            <edsp:styleProps>
                <edsp:styleProp styleRef="mobEuro" />
            </edsp:styleProps>
        </edsp:itemInfo>
    </item>

Now I try to fetch //item, but get not all the relevant informations (mainly: edsp:contact and geo:lat)

NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"testhotels.xml"];

NSData *XMLData   = [NSData dataWithContentsOfFile:XMLPath];

CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];

NSLog(@"Starting XML Parsing");

NSArray *nodes = NULL;

for (CXMLElement *node in nodes) {

    item = [[NSMutableDictionary alloc] init];

    int counter;

    for(counter = 0; counter < [node childCount]; counter++) {

    //  [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];

        NSString * value = [[[node childAtIndex:counter] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        if ([value length] != 0){

            [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] localName]]; //localName]];

        }



    }

    [res addObject:item];

    NSLog(@"test 1: %@", [[item valueForKey:@"edsp"] stringValue]);

    [item release];

}

NSLog(@"%@", res);

[res release];

And this is the LOG File:

{
    description = "Betrieben wird ein 4 Sterne Hotel mit ca. 140 Betten.  Mit 29.04.2008 wurde die Einzelfirma Christine Kr\U00f6th in die gegenst\U00e4ndliche Einzelfirma eingebracht.";
    guid = PN1VW;
    itemExt = "\n\t\t\t\t\n\t\t\t\t\thttp://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t+4347342660\n\t\t\t\t\t\t+434734406\n\t\t\t\t\t\[email protected]\n\t\t\t\t\t\thttp://www.katschberghof.at\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t";
    link = "http://test.dataapi.herold.at/search?aId=yasssu&auth=MjAxMDExMDgwNTAwMDA6TkRobU1HVXdNVGt6T1RabFpUQTJZalV4WXpBeE1qa3pZbUZsTmpjM01qST0NCg%3D%3D&c=15&provider=&q=PN1VW&type=yp_detail";
    point = "\n\t\t\t\t47.0579478809204\n\t\t\t\t13.6152591216261\n\t\t\t";
    title = "Hotel Katschberghof";
    uid = 92090;
}

Thanks for any suggestions how to solve this issue...

BR,

Stefan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-10-08 03:31:39

你必须解析所有相关的子节点:

for (CXMLElement *node in nodes) {

    for (CXMLNode *childNode1 in [node children]) {

        NSString *nodeName1 = [childNode1 name]; // should contain item_1 in first iteration
        NSString *nodeValue1 = [[childNode1 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

        NSLog(@"NodeName1, NodeValue1: %@, %@", nodeName1, nodeValue1);


        if ([[childNode1 name] isEqualToString:@"title"]) {

            NSLog(@"I am here!");
        [item setObject:nodeValue1 forKey:nodeName1]; 
        [res addObject:item];

        }


        for (CXMLNode *childNode2 in [childNode1 children]) {

        //  NSString *nodeName2 = [childNode2 name]; // should contain item_1 in first iteration
        //  NSString *nodeValue2 = [[childNode2 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

        //  NSLog(@"NodeName2, NodeValue2: %@, %@", nodeName2, nodeValue2);

            for (CXMLNode *childNode3 in [childNode2 children]) {

                //NSString *nodeName3 = [childNode3 name]; // should contain item_1 in first iteration
                //NSString *nodeValue3 = [[childNode3 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                //NSLog(@"NodeName3, NodeValue3: %@, %@", nodeName3, nodeValue3);

                for (CXMLNode *childNode4 in [childNode3 children]) {

                //  NSString *nodeName4 = [childNode4 name]; // should contain item_1 in first iteration
                //  NSString *nodeValue4 = [[childNode4 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                //  NSLog(@"NodeValue4: %@", nodeValue4);

                    for (CXMLNode *childNode5 in [childNode4 children]) {

                    //  NSString *nodeName5 = [childNode5 name]; // should contain item_1 in first iteration
                    //  NSString *nodeValue5 = [[childNode5 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                    //  NSLog(@"NodeName5, NodeValue5: %@, %@", nodeName5, nodeValue5);

                    }
                }

            }

        }

    }


    [item release];
}

you have to parse thru all the relevant childNodes:

for (CXMLElement *node in nodes) {

    for (CXMLNode *childNode1 in [node children]) {

        NSString *nodeName1 = [childNode1 name]; // should contain item_1 in first iteration
        NSString *nodeValue1 = [[childNode1 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

        NSLog(@"NodeName1, NodeValue1: %@, %@", nodeName1, nodeValue1);


        if ([[childNode1 name] isEqualToString:@"title"]) {

            NSLog(@"I am here!");
        [item setObject:nodeValue1 forKey:nodeName1]; 
        [res addObject:item];

        }


        for (CXMLNode *childNode2 in [childNode1 children]) {

        //  NSString *nodeName2 = [childNode2 name]; // should contain item_1 in first iteration
        //  NSString *nodeValue2 = [[childNode2 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

        //  NSLog(@"NodeName2, NodeValue2: %@, %@", nodeName2, nodeValue2);

            for (CXMLNode *childNode3 in [childNode2 children]) {

                //NSString *nodeName3 = [childNode3 name]; // should contain item_1 in first iteration
                //NSString *nodeValue3 = [[childNode3 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                //NSLog(@"NodeName3, NodeValue3: %@, %@", nodeName3, nodeValue3);

                for (CXMLNode *childNode4 in [childNode3 children]) {

                //  NSString *nodeName4 = [childNode4 name]; // should contain item_1 in first iteration
                //  NSString *nodeValue4 = [[childNode4 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                //  NSLog(@"NodeValue4: %@", nodeValue4);

                    for (CXMLNode *childNode5 in [childNode4 children]) {

                    //  NSString *nodeName5 = [childNode5 name]; // should contain item_1 in first iteration
                    //  NSString *nodeValue5 = [[childNode5 stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // should contain 'text' in first iteration

                    //  NSLog(@"NodeName5, NodeValue5: %@, %@", nodeName5, nodeValue5);

                    }
                }

            }

        }

    }


    [item release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文