<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
答案 0 :(得分:1)
使用TBXML解析XML内容.. http://tbxml.co.uk/
或查看本教程中的NSXML link
答案 1 :(得分:0)
使用本指南How to chose the best xml parser...,我发现TBXML是您案例中的最佳选择
答案 2 :(得分: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方法。希望这会帮助你。