tags:

views:

15

answers:

1

Here's an XML file I want to import into Cocoa:

 <?xml version='1.0'?>
    <Root xmlns='http://www.abc.uk' version='1.0' name='full'>
      <child1 version='2.0'>
        <value1>
           <user>abc</user>
           <pass>xyz</pass>
        </value1>
     </child1>
     <child2>
        <imp>12345</imp>
     </child2>
   </Root>

Now if I add all the XML info using the following type of code:

     NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"Root"];
     [root addAttribute:[NSXMLNode attributeWithName:@"xmlns" stringValue:@"NSXMLElement        

     [root addAttribute:[NSXMLNode attributeWithName:@"version" stringValue:@"2.0"]];
     [root addAttribute:[NSXMLNode attributeWithName:@"name" stringValue:@"full"]];


     NSXMLElement *childElement1 = [[NSXMLElement alloc] initWithName:@"child1"];
     [childElement1 addAttribute:[NSXMLNode attributeWithName:@"version"   
         stringValue:@"2.0"]];
     [root addChild:childElement1];
     [childElement1 release];

This does not create the XML as I would want it to. The end XML looks like:

     <?xml version='1.0'?>
    <Root xmlns='http://www.abc.uk' version='1.0' name='full'>
      <child1 version='2.0'> </child1>
        <value1> </value1>
           <user>abc</user>
           <pass>xyz</pass>

          <child2></child2>
          <imp>12345</imp>

   </Root>

How do I enter it correctly ? Thanks

+1  A: 

Add the user and pass elements to the value element, and the value element to the child1 element, and the imp element to the child2 element. From your output, it looks like you're just adding everything to the Root element.

Peter Hosey
doh. Thanks, I'll give that a try.