2 lantianyiming lantianyiming 于 2013.05.16 11:10 提问

求助: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
KindAzrael   2013.05.17 00: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);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!