我想使用TSQL从此Web服务响应中检索CUSTOMERNO。请注意,这是我得到的确切xml文件。提前致谢。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>
<CreateCustomerResponse xmlns="http://tempuri.org/">
<CreateCustomerResult><RESPONSEINFO><STATUS><TRANSACTIONNO>60878693</TRANSACTIONNO><ERRORNO>1002</ERRORNO><MESSAGE>Success</MESSAGE></STATUS><CUSTOMERNO>9021325146</CUSTOMERNO></RESPONSEINFO>
</CreateCustomerResult></CreateCustomerResponse>
</soap:Body></soap:Envelope>
答案 0 :(得分:0)
假设您的XML被读入xml类型变量,可以像这样完成:
DECLARE @xml XML=
N'<RESPONSEINFO>
<STATUS>
<TRANSACTIONNO>60878693</TRANSACTIONNO>
<ERRORNO>1002</ERRORNO>
<MESSAGE>Success</MESSAGE>
</STATUS>
<CUSTOMERNO>9021325146</CUSTOMERNO>
</RESPONSEINFO>';
SELECT @xml.value(N'(/RESPONSEINFO/CUSTOMERNO)[1]',N'bigint')
您必须首先阅读包装的XML并从那里阅读:
DECLARE @xml XML=
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateCustomerResponse xmlns="http://tempuri.org/">
<CreateCustomerResult><RESPONSEINFO><STATUS><TRANSACTIONNO>60878693</TRANSACTIONNO><ERRORNO>1002</ERRORNO><MESSAGE>Success</MESSAGE></STATUS><CUSTOMERNO>9021325146</CUSTOMERNO></RESPONSEINFO>
</CreateCustomerResult>
</CreateCustomerResponse>
</soap:Body>
</soap:Envelope>';
SELECT CAST(@xml.value(N'(/*:Envelope/*:Body/*:CreateCustomerResponse/*:CreateCustomerResult/text())[1]',N'nvarchar(max)') AS XML).value(N'(/RESPONSEINFO/CUSTOMERNO)[1]',N'bigint')
答案 1 :(得分:0)
一种方法是使用下面的代码片段 -
onSelectRow: function (id) {
var rid = jQuery('#tblJQGridBereitschaft').jqGrid("getGridParam", "selrow");
if (rid) {
var row = jQuery('#tblJQGridBereitschaft').jqGrid("getRowData", rid);
}
var bs_id = row.ID;
function seturl(bs_id){
jQuery("#tblJQGridBereitschaftFahrtkosten").setGridParam({ loadonce: false })
jQuery("#tblJQGridBereitschaftFahrtkosten").setGridParam({ datatype: "json" })
jQuery("#tblJQGridBereitschaftFahrtkosten").setGridParam({ url: '@Url.Action("GetFahrtkosten", "Bereitschaft")?BS_ID=' + bs_id +'', page: 1 }).trigger('reloadGrid');
jQuery("#tblJQGridBereitschaftFahrtkosten").setGridParam({ editurl: '@Url.Action("ModifyFahrtkosten", "Bereitschaft")?BS_ID=' + bs_id, page: 1 }).trigger('reloadGrid');
// Here I need the "addurl"
jQuery("#tblJQGridBereitschaftFahrtkosten").setGridParam({ loadonce: true })
}
seturl(bs_id);
$("#headerFahrtkosten").show();
$("#jqgrid_containerfahrtkosten").show();
},
修改:根据更改后的问题,修改了代码段 -
DECLARE @xmltext XML = N'<RESPONSEINFO><STATUS><TRANSACTIONNO>60878693</TRANSACTIONNO><ERRORNO>1002</ERRORNO><MESSAGE>Success</MESSAGE></STATUS><CUSTOMERNO>9021325146</CUSTOMERNO></RESPONSEINFO>'
SELECT T.C.value('CUSTOMERNO[1]', 'varchar(255)') FROM @xmltext.nodes('/RESPONSEINFO') T(C)