NSXMLParserDelegate目标c

时间:2016-12-19 14:44:10

标签: ios objective-c

如何解析<param name="Weight">630.00 гр</param>以获取630?当我使用以下内容时,我会获得elementName = param,但attributeDict只包含字典 - "name":"Weight"

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
   attributes: (NSDictionary *)attributeDict

1 个答案:

答案 0 :(得分:1)

您需要做的就是使用以下功能。

attributeDict

"name":"Weight"包含630标记时,您需要存储状态。比解析器会调用上面的函数,你应该能够从那里读取 <?php //if you want to call page for multiples time w.r.t array //then uncomment loop start & end) ?> <?php //foreach ($inputkeywordsArr as $singleKeyword) { $url="http://localhost/projectname/testpage.php"; $params['Keywordname'] = "testValue";//$singleKeyword post_async($url, $params); //}//foreach ($inputkeywordsArr end ?> <?php /* * Executes a PHP page asynchronously so the current page does not have to wait for it to finish running. * */ function post_async($url, array $params) { foreach ($params as $key => &$val) { if (is_array($val)) $val = implode(',', $val); $post_params[] = $key.'='.urlencode($val); } $post_string = implode('&', $post_params); $parts=parse_url($url); $fp = fsockopen($parts['host'], isset($parts['port'])?$parts['port']:80, $errno, $errstr, 30); $out = "GET ".$parts['path']."?$post_string"." HTTP/1.1\r\n";//you can use POST instead of GET if you like $out.= "Host: ".$parts['host']."\r\n"; $out.= "Content-Type: application/x-www-form-urlencoded\r\n"; $out.= "Content-Length: ".strlen($post_string)."\r\n"; $out.= "Connection: Close\r\n\r\n"; fwrite($fp, $out); fclose($fp); } ?>