[英]How to obtain an orphan boolean xml value from a string
我正在使用API,該API返回無法獲取的一些XML數據。
成功登錄后,會話密鑰將通過身份驗證,並且API返回布爾值'true'。
格式如下:
This XML file does not appear to have any style information associated with it.
document tree is shown below.
<boolean xmlns="http://tessiturasoftware.com/">true</boolean>
在其他XML數據已使用更多嵌套結構進行格式化的情況下,我已經能夠使用以下PHP來提取數據
$prodresponse = curl_exec($getproductions);
if(curl_errno($getproductions))
{
echo 'Curl error: Unable to obtain session ID ' . curl_error($getproductions);
}
else{
$xmlContent = simplexml_load_string($prodresponse);
echo $prodresponse;
foreach($xmlContent->xpath('//Production')as$prod){
$prodid= $prod->prod_season_no;
echo "<form action='GetProductionDetail.php' method='GET'>";
echo "<h1>".$prod->prod_desc." </h1> <input type='submit' value='Book Now'>
<input type='hidden' name='prodid' value=$prodid /></form>";
}
}
但是,當我嘗試使用以下命令返回布爾值並移至帳戶詳細信息頁面時,未返回任何數據
$response2 = curl_exec($login);
$xmlContent = simplexml_load_string($response2);
if(curl_errno($login))
{
echo 'Curl error: Unable to login ' . curl_error($login);
}
else {
echo 'test';
foreach($xmlContent->xpath('boolean') as $bool) {
echo $bool;
echo 'test';
}
if ($bool=='true'){
echo'test';
header("Location: GetAccountDetails.php");
}
}
請有人告訴我是否做錯了什么,是否與simplexml_load_string有關,或者是否有助於創建simpleXMLObject等...?
謝謝
里海
int number= getResources().getInteger(R.integer.yourNumber);
XML具有名稱空間定義。 因此,元素的“實際/內部”名稱為{http://tessiturasoftware.com/}:boolean
。 要獲取此元素而不忽略名稱空間,您需要為其注冊一個前綴。 SimpleXML為此具有方法registerXpathNamespace()
。 之后,您可以將前綴用作名稱空間字符串的別名。 如果您注冊tess
該元素可以尋址為tess:boolean
。
我更喜歡DOM,因為它使我可以執行更復雜的Xpath,例如將結果轉換為字符串並進行比較。
$dom = new DOMDocument();
$dom->loadXml('<boolean xmlns="http://tessiturasoftware.com/">true</boolean>');
$xpath = new DOMXpath($dom);
$xpath->registerNamespace('tess', 'http://tessiturasoftware.com/');
var_dump(
$xpath->evaluate('string(/tess:boolean) = "true"')
);
節目輸出
bool(true)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.