求助: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个回答

如果不想用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
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问