怎麼解析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>
如果不想用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);