views:

49

answers:

2

I have constructed an XML tree from an XML file. While constructing I do initWithKnd: or initWithKind: options: method.

How can I check if a node is of Element or CDATA or ay other kind while tracing the XML tree.

+1  A: 

To kind of a NSXMLNode is given by method kind, the return value is from enum NSXMLNodeKind.

NSXMLNodeKind kind = [node kind];

Note that there is no value for CDATA nodes. These become text nodes as the difference between text and CDATA is not preserved in the API.

Lachlan Roche
A: 

While tracing the XML tree, one can retrieve the current node, then check if the node kind belongs to element or CDATA or any other kind.

NSArray *array = [rootNode children];
NSXMLNode *node = [array objectAtIndex:index];

if([node kind] == NSXMLElementKind )// depending on one's requirement
{
    // doSomething
}
iSight
@iSight This just restates my answer.
Lachlan Roche