2014-10-06 85 views
0

我決定使用XFormat節點從使用PHP的API調用中獲取我的JSON POSTFIELDS。下面是 從JSON字符串轉化爲爲XMLDocument的XML數據的結果:Flowgear中未定義名稱空間前綴'salesValue'

<root> 
    <salesValue>5000</salesValue> 
    <authorId>2</authorId> 
</root> 

https://developers.flowgear.net/kb/Node:XPath_Match讀我想出了下面的XPath 抓住這些價值觀很感興趣,並注入他們對我的SQL查詢:

  • salesValue:根/ salesValue
  • AUTHORID:根/ AUTHORID

我已經選擇XML作爲我的轉義價值,該屬性不知道它應該是哪一個。我得到的錯誤是:

(XFormat 1.0.0.1):名稱空間前綴'salesValue'未定義。

我想這個問題與我如何格式化我的XPath,試圖獲取這些值。在我XFormat節點表達屬性的SQL查詢如下所示:

SELECT `Book`.`id` , `Book`.`name` , `Book`.`isbn` , `Book`.`quantity_in_stock` , `Book`.`price`  , (`Book`.`quantity_in_stock` * `Book`.`price`) AS `sales`, 
concat(`Author`.`name`, ' ', `Author`.`surname`) AS `author` FROM `books` AS `Book` LEFT JOIN  authors AS `Author` ON (`Book`.`author_id` = `Author`.`id`) 
WHERE (`Book`.`quantity_in_stock` * `Book`.`price`) > {salesValue} AND `Book`.`author_id` = " {authorId}" 

我應該有這些值在查詢注入我能夠繼續前進。下面是我的腳本使用通過API調用的工作流程:

   try{ 
    $results = invokeFlowgear("https://domain.flowgear.io/authorbooksaleslist", "login", "passwrd", 30, 
     array(
     'salesValue' => 5000.00, 
     'authorId' => 2 
    )); 

    var_dump($results); 


      }catch(Exception $exc){ print $exc->getMessage(); } 

預先感謝您...

回答

0

在XPath的元素的地址最多可以有三個部分:

  1. 本地名稱或*(所有)元素:foohtml - 這是強制性的
  2. 一個namepspace前綴/別名:n1:fooxhtml:html - 沒有前綴,意味着沒有命名空間
  3. 的軸定義元素的初始列表:children::foofollowing-sibling::xhtml:div - 默認爲children

你的XML沒有命名空間。它只是格格不入。所以提供'salesValue'或'authorId'作爲名稱空間前綴是錯誤的。

從文檔根尋址的值:

  • /root/salesValue
  • /root/authorId

我認爲TEST1:該示例中的鏈接的頁面只是提供一個標識符,以XPath表達式而不是它的一部分。

相關問題