【发布时间】:2010-09-16 22:52:22
【问题描述】:
我有这个已导入 Cocoa 的 XML 文件,并想修改一个值。我怎么做 ?好像没有什么好的例子。 我将此文件导入 Cocoa(正常工作),现在想更改 imp 的值,然后再将其传输到服务器。我该怎么做呢?谢谢
<?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>
我有这个解决方案,但它没有按我希望的那样工作。
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl
options:NSXMLDocumentTidyXML error:&err];
NSArray *children = [[xmlDoc rootElement] children];
int i, count = [children count];
//loop through each child
for (i=0; i < count; i++)
{
NSXMLElement *child = [children objectAtIndex:i];
NSLog(@"child Name is %@", child.name);
if ([child.name isEqual:@"child2"])
{
[[child attributeForName:@"imp"] setStringValue:@"4567"];
break;
}
}
【问题讨论】:
-
NSLog(@"值为 %@",[child childAtIndex:0]);让我得到 imp 参数的值。仍在寻找访问和更改它的方法。