【问题标题】:How to parse xml tags with space in iPhone?如何在 iPhone 中解析带空格的 xml 标签?
【发布时间】:2012-09-15 17:23:42
【问题描述】:
<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

【问题讨论】:

    标签: iphone ios xml xml-parsing


    【解决方案1】:

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

    或查看本教程以获取 NSXML link

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:
         - (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参数中获取它。用上面的 sn-p 覆盖代码中的 didStartElement 方法。希望对您有所帮助。

        【讨论】:

        • 感谢您的回复,但是...我的 attributeDict 有 0 个键值对
        猜你喜欢
        • 1970-01-01
        • 2012-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多