سؤال

This inserts a new element and child at the very bottom of the doc within the "main" root:

    NSXMLElement *root = [[xmlDoc rootElement] initWithName:@"main"];

    NSXMLElement *firstElement = [[NSXMLElement alloc] initWithName:@"first"];
    [root addChild:firstElement];

    NSXMLElement *secondElement = [NSXMLNode elementWithName:@"second"];
    [firstElement addChild:secondElement];

I need this to be inserted up top of the doc as the first or second node.. How can I do this?

Thanks.

-paul.

EDIT:

Ugh ... I can't believe it was this easy ...

 [root insertChild:firstElement atIndex:1];
هل كانت مفيدة؟

المحلول

This solved it:

[root insertChild:firstElement atIndex:1];

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top