我正在使用PHP發送XML到Web服務器,並且服務器返回XML響應。我需要幫助解析響應中的值!我已閱讀過SimpleXML指令,但我的理解是,所有這些僅適用於XML數據已經創建但需要解析的情況。這是迄今爲止我的PHP腳本:He!p with SimpleXML for PHP response in PHP
<?php
$ch = curl_init("http://api.online-convert.com/queue-insert");
$count = $_POST['count'];
$file = "testdoc2.txt";
$fh = fopen($file, 'w');
$carriageReturn = "\n";
fwrite($fh, $count);
fclose($fh);
$request["queue"] = file_get_contents($count);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
$xmlstr = simplexml_load_string($response);
$file = "testdoc.txt";
$fh = fopen($file, 'w');
$carriageReturn = "\n";
fwrite($fh, $xmlstr);
fclose($fh);
?>
需要被解析的XML響應是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<queue-answer>
<status>
<code>0</code>
<message>Successfully inserted job into queue.</message>
</status>
<params>
<downloadUrl>http://www.online-convert.com/result/35f6ddbcc2ca58e7e98addc7c2efd6eb</downloadUrl>
<hash>35f6ddbcc2ca58e7e98addc7c2efd6eb</hash>
</params>
</queue-answer>
我只需要提取值,並將其展示給用戶。我是一名iPhone開發人員。
我想,這可能是有用的http://debuggable.com/posts/parsing-xml-using-simplexml:480f4dfe-6a58-4a17-a133-455acbdd56cb –