Search code examples
objective-crecursionkissxml

Recursive loop over DDXMLDocument objective-c


I would like to loop recursively over DDXMLDocument, and to change the elements attributes.

How can I do it ? I currently have the document and the root element:

DDXMLDocument *theDocument = [[DDXMLDocument alloc] initWithXMLString:content options:0 error:&error];
    DDXMLElement *rootElement = theDocument.rootElement;

Solution

  • postfix tree walk implemented:

    -(void)processNode:(DDXMLNode *)node {
        if(node.kind == DDXMLElementKind) {
           //...
           for(DDXMLNode *child in node.children) {
               [self processNode:child];
           }
        }
    }