1

I have following NSXMLDocument:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<parent name=“abcd“>
    <content>
        <number>1234</number>
    </content>
</parent>

Now I would like to add another NSXMLElement directly behind the first <number>-entry

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<parent name=“abcd“>
    <content>
        <number>1234</number>
        <number>5678</number>
    </content>
</parent>

Just expected that I have to implement something like that, but it doesn’t work.

NSXMLElement *number = [[NSXMLElement alloc] initWithName:@“number“];
[number setStringValue:@“5678“];

NSXMLNode *parent = [xmlDoc childAtIndex:0];
NSXMLNode *content = [parent childAtIndex:0];

[content insertChild:number atIndex:1];

How can I add the new node/element to the NSXMLDocument?

3ef9g
  • 781
  • 2
  • 9
  • 19
  • 1
    Can you elaborate on what you mean by "doesn't work"? E.g. "it doesn't compile", or "even though I added the node, it doesn't seem to actually be added..". The code works here for me, provided you do appropriate casting from the generic `NSXMLNode` to `NSXMLElement`. – NSGod Jun 02 '16 at 17:14
  • Forgot the casting, thanks =) Now it works fine – 3ef9g Jun 03 '16 at 07:11

0 Answers0