2012-09-24 36 views
-1
<Messages> <Message activeFrom="2012-05-19T00:00:00+05:30" activeUpto="2012-12-31T00:00:00+05:30" createdById="1" createdByName="admin admin" createdOn="2012-05-19T15:23:56+05:30" description="As per client requirement AASTHA MULTIMEDIA is a multimedia education academy where students can innovatively create new designs with the help of advanced technology in multimedia which consider waterfall methodology.As per client requirement AASTHA MULTI" id="61" imageURL="3c1b77f9-2142-440d-ae8a-d0cbe2769c83.jpg" isActive="T" isTargetedToAffiliation="F" lastModifiedOn="2012-07-06T17:58:09+05:30" messageSubject="Consumer testing working with the wizeowl portal" organizationid="283" organizationImageName="b38e78fd-0f44-4a32-8d6e-35ca47d79dc4.png" organizationname="Biggin Scott" lastModifiedById="1" lastModifiedByName="admin admin"/> <Message activeFrom="2012-09-18T00:00:00+05:30" activeUpto="2012-09-30T00:00:00+05:30" createdById="495" createdByName="Jayul Mehta" createdOn="2012-05-21T15:16:57+05:30" description="test. http://www.google.com" id="62" imageURL="618dae63-9861-4702-add7-fea06cf2f403.png" isActive="T" isTargetedToAffiliation="F" lastModifiedOn="2012-08-30T12:15:09+05:30" messageSubject="test" organizationid="325" organizationImageName="2cc2c83e-144d-4687-b087-ef459ee4e3a1.jpg" organizationname="test org without email and web address" lastModifiedById="1" lastModifiedByName="admin admin"/> </Messages> 

這裏是我需要解析的字符串...我可以得到有兩個「消息」對象...但我無法獲得它的價值。如何在iPhone中用空格解析xml標籤?

以下方法未被調用。

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 

請有關如何解析這個XML類型的

回答

0
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
attributes:(NSDictionary *)attributeDict { 


    if([elementName isEqualToString:@"Message"]){ 
     NSString *activeFrom=[attributeDict valueForKey:@"activeFrom"]; 
     NSString *activeUpto=[attributeDict valueForKey:@"activeUpto"]; 
     NSString *createdById=[attributeDict valueForKey:@"createdById"]; 
     NSString *createdByName=[attributeDict valueForKey:@"createdByName"]; 
     NSString *description=[attributeDict valueForKey:@"description"]; 

     ....... so on ...... 

    } 



} 

@Dimple您希望xml字符串的值的方式,您可以從委託方法didStartElement傳遞的attributeDict參數中抓取它。通過上面的代碼片段覆蓋代碼中的didStartElement方法。希望這會幫助你。

+0

感謝您的回覆,但...我的attributeDict有0個鍵值對 –

+0

這是我的錯誤....感謝寶貴的答覆.... –