lantianyiming
lantianyiming
采纳率79.6%
2013-05-16 03:10 浏览 4.4k
已采纳

求助:IOS-解析HTML内容

怎么解析HTML文件?

在下面的代码中得到HTML文件, 只要BinarySecurityToken XML 节点之间数据。

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
 {
   if(_data)
  {
    //Here am getting the below HTML content
    NSString* content = [[NSString alloc] initWithData:_data
                                              encoding:NSUTF8StringEncoding];
  }
 }    
<input type="hidden" name="wa" value="wsignin1.0" />
<input type="hidden" name="wresult"
    value="<t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<t:Lifetime>
   <wsu:Created >2013-04-29T11:50:29.895Z</wsu:Created>
   <wsu:Expires>2013-04-29T12:00:29.895Z</wsu:Expires>
</t:Lifetime>
<wsp:AppliesTo>     
<EndpointReference>
<Address>urn:orin.converse</Address>
</EndpointReference></wsp:AppliesTo>
<t:RequestedSecurityToken>    
   <wsse:BinarySecurityToken>
         aHR0cCUzYSUyZiUyZnNjaGVtYWd0Sjk0JTNk
   </wsse:BinarySecurityToken>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    KindAzrael AldisZhan 2013-05-16 16:20

    如果不想用XML DOM去解析的话,仅仅试简单就想获取这个token数据 可以简单截取这串字符

      NSRange startTag = [xml rangeOfString:@"<wsse:BinarySecurityToken>"];
      NSRange endTag = [xml rangeOfString:@"</wsse:BinarySecurityToken>"];
      NSInteger location = startTag.location + startTag.length;
      NSInteger length = endTag.location - location;
      NSRange range = NSRangeFromString([NSString stringWithFormat:@"{%d, %d}", location, length]);
      NSString *token = [xml substringWithRange:range];
      NSLog(@"%@", token);
    
    点赞 评论 复制链接分享

相关推荐