开发者

nodesForXPath does not return any nodes: TouchXML

I'm consuming a Web Service using TouchXML and I'm unable to read the nodes as per the tutorial. I do receive the CXMLDocument element, however, my nodesForXPath call always returns NULL. What could be wrong?

XML Parsing code

NSMutableArray *res = [[NSMutableArray alloc] init];
N开发者_Python百科SData* valueData=[value dataUsingEncoding:NSUTF8StringEncoding];

    // Do something with the CXMLDocument* result
    CXMLDocument *result = [[[CXMLDocument alloc] initWithData:valueData options:0 error:nil] autorelease];

    NSArray *nodes = NULL;


    nodes = [result nodesForXPath:@"//Outputs" error:nil];

    NSLog (@"Nodes is %@\n", nodes);

    for (CXMLElement *node in nodes) {
        NSLog (@"Test");
        NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
        int counter;
        NSLog (@"Child Count is %@\n",[node childCount]);
        NSLog (@"Child node is%@\n",[[node childAtIndex:0] stringValue]);
        for(counter = 0; counter <= [node childCount]; counter++) {
            //  common procedure: dictionary with keys/values from XML node
            [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];


        }


        //[item setObject:[[node attributeForName:@"id"] stringValue] forKey:@"id"];  

        [res addObject:item];
        [item release];
    }

    //  and we print our results
    NSLog(@"%@", res);
    [res release];


}

XML:

    <Nodes>
    <Inputs>
        <name>TestProgram</name>
        </Inputs>
        <Outputs>
            <ReturnCode>0</ReturnCode>
            <ReturnMessage>Success</ReturnMessage>
            <NameDetails attr1="value1">Test Program</NameDetails>
            <NameInstance attr1="value1">
            <NameCharacteristics>
                <Dob>04-25-2011</Dob>
            </NameCharacteristics>
            </NameInstance>
        </Outputs>
</Nodes>

nodesForXPatch for //Outputs always returns NULL. I want to fetch the node value. I tried replacing Outputs with Dob and still get an empty set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜