1

I have constructed an XML tree structure 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.

Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77
boom
  • 5,856
  • 24
  • 61
  • 96
  • Exact duplicate of http://stackoverflow.com/questions/2400571 – Dave DeLong Mar 11 '10 at 14:50
  • 1
    @Dave this question asks about xml attribute name/value. The other question asked about xml node type. The questions are close, but different. – Lachlan Roche Mar 12 '10 at 11:06
  • @marc_s: The real reason to accept answers is not “incentive”, but so that future readers of the question know what the correct answer to the question is. – Peter Hosey Mar 13 '10 at 06:45

1 Answers1

3

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];
}
Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77