如何获取GDataXMLNode中XML节点的属性名称。
我需要从中获取“anyAttribute”和“anyAttribute2”...
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
有一种方法可以实现这一点,还是我应该尝试其他选项?
最佳答案
这是一个示例代码:
GDataXMLElement *anynode = [GDataXMLNode elementWithName:@"anynode"];
GDataXMLElement *anyAttribute = [GDataXMLNode attributeWithName:@"anyAttribute" stringValue:@"anyvalue"];
GDataXMLElement *anyAttribute2 = [GDataXMLNode attributeWithName:@"anyAttribute2" stringValue:@"123"];
[anynode addAttribute:anyAttribute];
[anynode addAttribute:anyAttribute2];
这段代码创建节点:
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
现在从任意节点提取属性值:
NSString *attribute1 = [anynode attributeForName:@"anyAttribute"].stringValue;
NSString *attribute2 = [anynode attributeForName:@"anyAttribute2"].stringValue;
关于objective-c - 如何获取 XML 节点的属性名称 - GDataXMLNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187546/