Hello,
I am trying to use NSXMLParser on the iPhone to parse a string that contains HTML, similar to the HTML shown below...
<html><head><title>Working...</title></head><body><form method="POST" name="hiddenform" action="http://xxx/zfp"><input type="hidden" name="wa" value="wsignin1.0" /><input type="hidden" name="wresult" value="<t:RequestSecurityTokenResponse Context="rm=0&amp;id=passive&amp;ru=%2fzfp%2f" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust&quot;>&lt;t:Lifetime>&lt;wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;>2010-06-20T03:41:10.782Z&lt;/wsu:Created> ...MORE STUFF HERE... </t:RequestSecurityTokenResponse>" /><input type="hidden" name="wctx" value="rm=0&id=passive&ru=%2fzfp%2f" /><noscript><p>Script is disabled. Click Submit to continue.</p><input type="submit" value="Submit" /></noscript></form><script language="javascript">window.setTimeout('document.forms[0].submit()', 0);</script></body></html>
What I am really trying to extract from the HTML are the value attributes of the three INPUT elements. In my didStartElement method, I check to see if the elementName is equal to "input", and, then look in the attributes NSDictionary object to get the value attribute.
Specifically what I am having trouble with is the "wresult" input field. When I get the "value" out of the NSDictionary, it seems to already be decoded (it was url encoded in the original HTML).
In other words, I want to get this from the NSDictionary when I read the "value" attribute for the "wresult" input...
<t:RequestSecurityTokenResponse Context="rm=0&amp; ...
...but instead what I get is this...
<t:RequestSecurityTokenResponse Context="rm=0& ...
Does anyone know a way to make NSXMLParser preserve the original url encoding in the attributes and just send me the encoded characters from the original string?
Here is my didStartElement code if that helps...
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"input"]) {
NSString* name = [attributeDict valueForKey:@"name"];
NSString* val = [attributeDict valueForKey:@"value"];
if (![val isEqualToString:@"Submit"]) {
NSLog(@"Found element...");
NSLog(@"Name:");
NSLog(name);
NSLog(@"Value:");
NSLog(val);
}
}
}
Thanks,
David