Ios5 如何在xcode 4.3中使用GDATEXML更改xml标记的值?
我不熟悉使用GDATXML解析xml文件。 我想更改文件中某个中间xml标记的值&将其写回文件 我有以下文件Ios5 如何在xcode 4.3中使用GDATEXML更改xml标记的值?,ios5,xml-parsing,xcode4.3,gdataxml,Ios5,Xml Parsing,Xcode4.3,Gdataxml,我不熟悉使用GDATXML解析xml文件。 我想更改文件中某个中间xml标记的值&将其写回文件 我有以下文件 <sheetData> <row r="7" spans="5:6" x14ac:dyDescent="0.25"> <c r="E7" t="s"> <v>0</v> </c> <c r="F7" t="s"> <v>1</v> </c&
<sheetData>
<row r="7" spans="5:6" x14ac:dyDescent="0.25">
<c r="E7" t="s">
<v>0</v>
</c>
<c r="F7" t="s">
<v>1</v>
</c>
</row>
<row r="8" spans="5:6" x14ac:dyDescent="0.25">
<c r="E8" t="s">
<v>2</v>
</c>
<c r="F8">
<v>9890234654</v>
</c>
</row>
</sheetData>
0
1.
2.
9890234654
我想将电话号码('9890234654')的值更新为9503452366。
如何在iOS中使用GDATEXML来实现这一点?(我使用的是xcode 4.3.2)
我找不到任何方法直接替换原始xml树中的标记值
感谢您的帮助。
谢谢。您是否创建了XML文件/数据?我建议您为节点设置名称空间,以便更容易跟踪它们。例如:
<sheetData xmlns="http://mypage.net/sheetdata">
<row r="7" spans="5:6" x14ac:dyDescent="0.25" xmlns="http://mypage.net/r7">
<c r="E7" t="s">
<v>0</v>
</c>
<c r="F7" t="s">
<v>1</v>
</c>
</row>
<row r="8" spans="5:6" x14ac:dyDescent="0.25" xmlns="http://mypage.net/r8">
<c r="E8" t="s">
<v>2</v>
</c>
<c r="F8">
<v>9890234654</v>
</c>
</row>
</sheetData>
//The sample xml data is assigned to this NSData object: myXMLData
//Create a GDataXMLDocument
NSError *error = nil;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:myXMLData options:0 error:&error];
//build a namespace dictionary
NSDictionary *ns = [NSDictionary dictionaryWithObjectsAndKeys:@"http://mypage.net/sheetdata", @"sd", @"http://mypage.net/r7", @"r7", "http://mypage.net/r8", @"r8", nil];
//Now here are some codes to change the value
NSError *err = nil;
GDataXMLNode *row8 = [[doc nodesForXPath:@"//r8:row" namespace:ns error:&err] objectAtIndex:0];
//Need to change value of second node
GDataXMLNode *f8 = [[row8 children] objectAtIndex:1];
GDataXMLNode *f8v = [[f8 children] objectAtIndex:0];
f8v.stringValue = @"9503452366";
//doc now has the xml with updated value. Just get the XML data, doc.XMLData, from it then convert it as you please