开发者

Importing XML into Cocoa issues

Here's an XML file I want to import i开发者_开发技巧nto 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜