如何獲取XML節點的屬性名稱GDataXMLNode。如何獲取XML節點的屬性名稱 - GDataXMLNode
我需要得到「anyAttribute」,並從這個「anyAttribute2」 ......
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
有一種方法爲或者我應該嘗試其他的選擇嗎?
如何獲取XML節點的屬性名稱GDataXMLNode。如何獲取XML節點的屬性名稱 - GDataXMLNode
我需要得到「anyAttribute」,並從這個「anyAttribute2」 ......
<anynode anyAttribute="anyvalue" anyAttribute2="123"/>
有一種方法爲或者我應該嘗試其他的選擇嗎?
有一個名爲「AQXMLParser」的開源組件,具有此功能。試試看: http://www.alexcurylo.com/blog/2009/06/09/code-aqxmlparser/
下面是一個示例代碼:
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;
ty爲答案,我做了一個壞問題...我知道如何提取屬性和節點的值。我需要從節點獲取屬性的名稱或屬性列表。不要擔心這個問題...我改變了我的XML文件。 Ty再次。 – 2012-03-01 04:18:55
對於你的情況(和大多數其他情況),GDataXMLNode實際上將是GDataXMLElement子類的實例,因此只需將GDataXMLNode向下壓縮爲GDataXMLElement,然後通過名稱(如果你知道它們)或通過屬性GDataXMLElement實例。
ty我要去試試它... – 2012-02-08 13:58:45