2012-02-08 58 views

回答

1

下面是一個示例代碼:

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"/> 

我們瞭解anynode提取屬性值

NSString *attribute1 = [anynode attributeForName:@"anyAttribute"].stringValue; 
    NSString *attribute2 = [anynode attributeForName:@"anyAttribute2"].stringValue; 
+0

ty爲答案,我做了一個壞問題...我知道如何提取屬性和節點的值。我需要從節點獲取屬性的名稱或屬性列表。不要擔心這個問題...我改變了我的XML文件。 Ty再次。 – 2012-03-01 04:18:55

1

對於你的情況(和大多數其他情況),GDataXMLNode實際上將是GDataXMLElement子類的實例,因此只需將GDataXMLNode向下壓縮爲GDataXMLElement,然後通過名稱(如果你知道它們)或通過屬性GDataXMLElement實例。

相關問題