lr_xml_get_values()
檢索查詢找到的XML元素的值。
int lr_xml_get_values(<規範列表> [,<可選規範列表>] [,LAST]);
參數說明:
List of specifications:對於以下所需規格列表,請使用以下字符串格式:
“Specification = value”
XML:要查詢的XML輸入字符串
ValueParam:存儲查詢結果的輸出參數的名稱。如果不存在,則創建它。
Query:對輸入字符串XML的XML查詢或快速查詢。您可以指定元素或屬性。
List of optional specifications:對於以下可選規格列表,請使用以下字符串格式:
“Specification = value”
SelectAll:如果爲“yes”,則將處理與查詢匹配的所有元素。如果“否”,則僅處理第一個匹配。默認值爲“no”。請參閱多查詢匹配
NotFound:請參見繼續出錯
LAST:指示可選規範列表結束的標記
lr_xml_get_values函數查詢XML輸入字符串XML以查找與查詢條件匹配的值。
示例:lr_xml_get_values
有關使用lr_xml_get_values的更多示例,請參閱示例1 - 在XML查詢的示例腳本中執行查詢和值相關函數。
實施例1
以下示例使用lr_xml_get_values搜索員工的姓名。
首先,一個簡單的XML字符串存儲在參數XML_Input_Param中。然後,使用XPath查詢字符串“/ employee / name”調用lr_xml_get_values。然後,將在XML_Input_Param參數字符串上處理此查詢。查詢的結果存儲在OutputParam參數中。 OutputParam的值使用lr_eval_string進行計算。
#include“as_web.h”
char * xml_input =
“<employee>”
“<name> John Smith </ name>”
“<cubicle> 227 </ cubicle>”
“</ employee>”;
Action(){
lr_save_string(xml_input,“XML_Input_Param”); //將輸入保存爲參數
lr_xml_get_values(“XML = {XML_Input_Param}”,
“ValueParam = OutputParam”,
“Query = / employee / name”,
LAST);
lr_output_message(lr_eval_string(“Query result = {OutputParam}”));
return 0;
}}
輸出:
Action.c(13):“lr_xml_get_values”成功,處理1個匹配
Action.c(18):查詢結果= John Smith
實施例2
以下示例與示例1類似,但檢索到多個值。該查詢從XML輸入字符串xml_input檢索所有電話機擴展。
#include“as_web.h”
char * xml_input =
“<acme_org>”
“<accounts_dept>”
“<employee>”
“<name> John Smith </ name>”
“<cubicle> 227 </ cubicle>”
“<extension> 2145 </ extension>”
“</ employee>”
“</ accounts_dept>”
“<engineering_dept>”
“<employee>”
“<name> Sue Jones </ name>”
“<extension> 2375 </ extension>”
“</ employee>”
“</ engineering_dept>”
“</ acme_org>”;
Action(){
int i,NumOfValues;
char buf [64];
lr_save_string(xml_input,“XML_Input_Param”); //將輸入保存爲參數
NumOfValues = lr_xml_get_values(“XML = {XML_Input_Param}”,
“ValueParam = OutputParam”,
“Query = / acme_org / * / employee / extension”,
“SelectAll = yes”,LAST);
for(i = 0; i <NumOfValues; i ++){/ *打印OutputParam *的多個值*
sprintf(buf,“Retrieved value%d:{OutputParam_%d}”,i + 1,i + 1);
lr_output_message(lr_eval_string(buf));
}}
return 0;
}}
輸出:
Action.c(34):檢索值1:2145
Action.c(34):檢索值2:2375