0

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.

Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77
boom
  • 5,856
  • 24
  • 61
  • 96

2 Answers2

1

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
  • 25,678
  • 5
  • 79
  • 77
0

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
}
Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77
boom
  • 5,856
  • 24
  • 61
  • 96