提问人:tyrese humphreys 提问时间:5/10/2023 更新时间:5/10/2023 访问量:51
soap xml 到 JS 变量
soap xml to JS variable
问:
使用 Postman,我从 WSDL URL 获得响应,我得到 SOAP 响应都很好,现在我需要在网站上使用数据,以便我可以将用户输入的数据与我得到的响应进行比较,我设法使用 php-curl 在我的网页上获得响应
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:web=\"http://www.dataaccess.com/webservicesserver/\">\n
<soapenv:Header/>\n
<soapenv:Body>\n
<web:NumberToWords>\n
<ubiNum>100</ubiNum>\n
</web:NumberToWords>\n
</soapenv:Body>\n
</soapenv:Envelope>",
CURLOPT_HTTPHEADER => array("content-type: text/xml"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
输出
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<soap-env:body>
<n0:zfi_mf_ws_consulta_clienteresponse xmlns:n0="urn:sap-com:document:sap:rfc:functions">
<e_datos>
<kunnrdf>123</kunnr>
<name1>name</name1>
<land1>VE</land1>
<stras>street</stras>
<ort01>SAN FRANCISCO</ort01>
<telf1>0261-215012</telf1>
<stcd1>J-0701721725-7</stcd1>
<stcd1_sg>J07017252252177</stcd1_sg>
<smtp_addr>[email protected]</smtp_addr>
<tatyp_1>Flete</tatyp_1>
<taxkd_1>0</taxkd_1>
<tatyp_2> Producto</tatyp_2>
<taxkd_2>1</taxkd_2>
</e_datos>
<e_respuesta>
<tipo>
<clase>
<nro>000</nro>
<mensaje></mensaje>
</clase>
</tipo>
</e_respuesta>
</n0:zfi_mf_ws_consulta_clienteresponse></soap-env:body>
</soap-env:header>
</soap-env:envelope>
如何仅获取值,然后用它来与另一个数据进行比较,看看它是否合适,另外我需要其余的用于其他用途(放入带有 js 的输入字段)
谢谢
答:
0赞
Arno Vantieghem
5/10/2023
#1
您可以将字符串解析为 XML,然后按 TagName 进行搜索,这是一个示例,我在其中获取了 Movie 对象列表。
var doc;
var parser = new DOMParser();
doc = parser.parseFromString(responseXML.data, 'text/xml');
var x = doc.getElementsByTagName("d4p1:Movie");
var movies = [];
for (var i= 0;i < x.length; i++)
{
movies.push({
id: x[i].getElementsByTagName("d4p1:Id")[0].childNodes[0].nodeValue
title: x[i].getElementsByTagName("d4p1:Title")[0].childNodes[0].nodeValue,
overview: x[i].getElementsByTagName("d4p1:Overview")[0].childNodes[0].nodeValue,
src: x[i].getElementsByTagName("d4p1:Poster")[0].childNodes[0].nodeValue
});
评论
0赞
tyrese humphreys
5/10/2023
感谢您的回答,但我收到一个错误 Uncaught ReferenceError:responseXML 未定义,我有一个 html 文件,其中有带有输入字段的 post 方法,用户输入一个数字然后得到响应,该响应要么是数据,要么是一条消息,说没有找到任何数据。加上阅读“d4p1:Movie”代表的剧本,对我来说会是“e_datos:kunnrdf”
0赞
Arno Vantieghem
5/11/2023
我在这里使用的responseXML是我从POST到Soap API的响应。我不熟悉您使用的语法,但我想它会和$response一样吗?你必须按照以下方式做一些事情var x = doc.getElementsByTagName("e_datos"); var kunnrdf = x[0].getElementsByTagName("kunnrdf"); var name1 = x[0].getElementsByTagName("name1");
评论