How to get attributes from an element in XML
I have constructed an XML tree structur开发者_运维知识库e of an XML file. I am able to trace the entire tree.
When i want to retrieve the attributes of an element, it is returning as NSXMlNode of kind NSXMLAttributeKind
. How can i extract the key value pairs in the attribute node.
The name and value of a NSXMLNode are given by methods name and stringValue respectively. For an attribute node, these are the attibute name and value.
The attributes of a NSXMLElement are given by method attributes, or a particular attribute can be accessed by name with method attributeForName:.
NSXMLNode *attr = [element attributeForName: @"data"];
NSString *name = [node name];
NSString *value = [node stringValue];
for( NSXMLNode *node in [element attributes] ) {
NSString *name = [node name];
NSString *value = [node stringValue];
}
精彩评论