Reputation: 51
How to get the Attribute name of a XML Node in GDataXMLNode.
I'll need get "anyAttribute" and "anyAttribute2" from this...
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
There is a method for that or should i try other option?
Upvotes: 2
Views: 2401
Reputation: 404
In your case (and most other cases) the GDataXMLNode will actually be the instance of the GDataXMLElement subclass, so simply downcast the GDataXMLNode to GDataXMLElement and extract attributes by their names (if you know them) or via the attributes property of the GDataXMLElement instance.
Upvotes: 1
Reputation: 1962
Here's a sample code:
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];
This piece of code creates the node:
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
Now to extract the attribute values from anynode:
NSString *attribute1 = [anynode attributeForName:@"anyAttribute"].stringValue;
NSString *attribute2 = [anynode attributeForName:@"anyAttribute2"].stringValue;
Upvotes: 1
Reputation: 14304
There is an open source component called "AQXMLParser" that has this feature. Give it a try: http://www.alexcurylo.com/blog/2009/06/09/code-aqxmlparser/
Upvotes: 0