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

这是我需要解析的字符串...我可以知道有两个“消息”对象...但是我无法获得其中的值。

未调用以下方法。

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

请回复如何解析这种类型的XML

4

3 回答 3

1

使用 TBXML 解析 XML 内容.. http://tbxml.co.uk/

或查看本教程教程以获取 NSXML链接

于 2012-09-24T09:07:38.287 回答
0

使用本指南How to choose the best xml parser...,我发现 TBXML 是您的最佳选择

于 2012-09-24T09:07:57.420 回答
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 方法。希望这会帮助你。

于 2012-09-24T09:21:00.287 回答