将XML导入到Cocoa问题 [英] Importing XML into Cocoa issues
本文介绍了将XML导入到Cocoa问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我要导入到Cocoa的XML文件:
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>
现在,如果我使用以下类型的代码添加所有XML信息:
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];
这不会像我想要的那样创建XML。
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>
如何正确输入?感谢
推荐答案
添加用户
和
元素添加到
值
元素,将值
元素添加到 child1
元素和 imp
元素添加到 child2
元素。从你的输出,看起来你只是添加一切到根
元素。
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.
这篇关于将XML导入到Cocoa问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文