作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不熟悉使用 GDataXML 来解析 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>
</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>
我想更新 phone no ('9890234654') 的值,比如说,9503452366。我如何在 iOS 中使用 GDataXML 来做到这一点?(我使用的是 xcode 4.3.2)
我找不到任何方法可以直接在原始 xml 树中替换标记值。
感谢任何帮助。谢谢。
最佳答案
您是否创建了 XML 文件/数据?我建议您为节点放置 namespace ,以便更容易跟踪它们。例如:
<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
关于ios5 - 如何在 xcode 4.3 中使用 GDataXML 更改 xml 标记的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12370293/
我是一名优秀的程序员,十分优秀!