我正在使用 C# 中的 SOAP 获取数据。 这是我得到的 SOAP 响应。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetApplicantInfoResponse xmlns="http://tempuri.org/">
<GetApplicantInfoResult xmlns:a="http://*****.*****.org/****/*******.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:DateOfBirth></a:DateOfBirth>
<a:Email></a:Email>
<a:FirstName></a:FirstName>
</GetApplicantInfoResult></GetApplicantInfoResponse>
</s:Body></s:Envelope>
然后使用 JavaScript
调用 .html
现在需要将数据绑定(bind)到HTML Table
。
最佳答案
使用 XML Parser然后 JavaScript 将数据添加到表中。
function getSoap() {
return '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
'<s:Body>' +
'<GetApplicantInfoResponse xmlns="http://tempuri.org/">' +
'<GetApplicantInfoResult xmlns:a="http://*****.*****.org/****/*******.Data" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
'<a:DateOfBirth></a:DateOfBirth>' +
'<a:Email>james@email.com</a:Email>' +
'<a:FirstName>James</a:FirstName>' +
'</GetApplicantInfoResult></GetApplicantInfoResponse>' +
'</s:Body></s:Envelope>';
}
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(getSoap(), "text/xml");
document.getElementById("firstname").innerHTML = xmlDoc.getElementsByTagName("a:FirstName")[0].childNodes[0].nodeValue;
document.getElementById("email").innerHTML = xmlDoc.getElementsByTagName("a:FirstName")[0].childNodes[0].nodeValue;
<table>
<tr>
<th>Firstname</th>
<th>Email</th>
</tr>
<tr>
<td id="firstname"></td>
<td id="email"></td>
</tr>
</table>
关于javascript - 如何使用 SOAP 响应绑定(bind) HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54918515/