views:

18

answers:

0

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"&gt;&lt;input type="hidden" name="wa" value="wsignin1.0" /><input type="hidden" name="wresult" value="&lt;t:RequestSecurityTokenResponse Context=&quot;rm=0&amp;amp;id=passive&amp;amp;ru=%2fzfp%2f&quot; xmlns:t=&quot;http://schemas.xmlsoap.org/ws/2005/02/trust&amp;quot;&gt;&amp;lt;t:Lifetime&gt;&amp;lt;wsu:Created xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&amp;quot;&gt;2010-06-20T03:41:10.782Z&amp;lt;/wsu:Created&gt; ...MORE STUFF HERE... &lt;/t:RequestSecurityTokenResponse>" /><input type="hidden" name="wctx" value="rm=0&amp;id=passive&amp;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...

&lt;t:RequestSecurityTokenResponse Context=&quot;rm=0&amp;amp; ...

...but instead what I get is this...

<t:RequestSecurityTokenResponse Context="rm=0&amp; ...

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