lr_xml_delete()
從XML字符串中刪除片段。
int lr_xml_delete(<規範列表> [,<可選規範列表] [,LAST]);
參數說明:
List of specifications:對於以下所需規格列表,請使用以下字符串格式:
“Specification = value”
XML:要查詢的XML輸入字符串
ResultParam:刪除片段後包含XML數據的輸出參數的名稱。
Query:對輸入字符串XML的XML查詢。
List of optional specifications:對於以下可選規格列表,請使用以下字符串格式:
“Specification = value”
SelectAll:如果爲“yes”,則將處理與查詢匹配的所有元素。如果“否”,則僅處理第一個匹配。默認值爲“no”。請參閱多查詢匹配
NotFound:請參見繼續出錯
LAST:表示可選規範列表結束的標記
lr_xml_delete函數查詢XML輸入字符串XML,並刪除與查詢條件匹配的XML樹的片段。您可以通過在XML查詢中指定元素名稱或其屬性來刪除元素。輸出參數ResultParam包含刪除後使用源文檔編碼的修改後的XML字符串。
注意:刪除元素的內容後,空元素e表示<e />。例如,從XML字符串“<a> <b> <c> </ c> </ b> </a>中刪除元素c後的字符串結果是:
“<a> <b /> </a>”
因爲元素b現在是空的。
示例:lr_xml_delete
以下示例在輸入字符串xml_input中搜索標記“<extension>”,然後將其刪除。結果字符串包含在ResultParam參數Result中。
有關使用lr_xml_delete的更多示例,請參閱刪除XML查詢的示例腳本中的元素。
#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>”
“</ acme_org>”;
Action(){
lr_save_string(xml_input,“XML_Input_Param”); //將輸入保存爲參數
lr_xml_delete(“XML = {XML_Input_Param}”,
“ResultParam = Result”,
“Query = / acme_org / accounts_dept / employee / extension”,
LAST);
lr_output_message(lr_eval_string(“刪除後的字符串:{Result}”)));
return 0;
}}
輸出:
Action.c(25):刪除後的字符串:<acme_org> <accounts_dept> <employee> <name> John Smith </ name> <cubicle> 227 </ cubicle> </ employee> </ accounts_dept> </ acme_org>