2

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?

3 Answers3

1

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.

maksa
  • 374
  • 5
  • 16
1

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;
yoninja
  • 1,952
  • 2
  • 31
  • 39
  • ty for the answer, I did a bad question ... I know how to extract the values of attributes and nodes. I'll need get the attribute's name or a list of attributes from a node. Don't worry about this question... i changed my XML file. Ty again. – Francisco Muñoz Diaz Mar 01 '12 at 04:18
0

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/

Stavash
  • 14,244
  • 5
  • 52
  • 80