【发布时间】:2025-11-25 22:15:01
【问题描述】:
我的问题是,我正在处理一个在 Flash 中制作的重构项目,并且必须将其转换为 SAUI5,为此我使用了一个肥皂网络服务。它包含 Web 服务的多个部分。 Ajax 调用如下所示:
`var oAppSettings = sap.ui.getCore().getModel("appSettings").getData();
var response;
var oData;
var oXMLModel = new sap.ui.model.xml.XMLModel();
var sReq = "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:web=\"http://webservice.cpb.dqw.sap.com\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <web:boeLogonWithToken>\n" +
" <!--Optional:-->\n" +
" <web:args0>"+oAppSettings.loginToken+"</web:args0>\n"
+
" </web:boeLogonWithToken>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
$.ajax({
url: oAppSettings.serverPath + ".AdminHttpSoap11Endpoint/",
method: "POST",
dataType: "xml",
data: sReq,
//processData:false,
contentType: "text/xml; charset=\"utf-8\"",
success: function (data, textStatus, jqXHR) {
response = data;
console.log(response);
console.log("Is a success!");
},
error: function (xhr, status) {
console.log("Error: : " + status);
},
complete: function (xhr, status) {
console.log(response);
setUpData();
}
});
function setUpData(){
oXMLModel.setData(response);
console.log(oXMLModel.getXML());
}`
我得到的回应是这样的:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:boeLogonWithTokenResponse
xmlns:ns="http://webservice.cpb.dqw.sap.com">
<ns:return xmlns:ax22="http://shared.cpb.dqw.sap.com/xsd"
xmlns:ax21="http://types.cpb.dqw.sap.com/xsd"
xmlns:ax24="http://types.sdk.boe.dqw.sap.com/xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ax21:CPBAdminResult">
<ax21:contentUpgradeVersion>0</ax21:contentUpgradeVersion>
<ax21:cpInfo xsi:nil="true" />
<ax21:errorData xsi:nil="true" />
<ax21:intValue xsi:nil="true" />
<ax21:projectInfo xsi:nil="true" />
<ax21:reservedData xsi:nil="true" />
<ax21:status>OK</ax21:status>
<ax21:stringArray xsi:nil="true" />
<ax21:stringValue xsi:nil="true" />
</ns:return>
</ns:boeLogonWithTokenResponse>
</soapenv:Body>
</soapenv:Envelope>`
我想知道如何通过SAPUI5的xml模型返回的xml进行解析。
谢谢
【问题讨论】:
-
您是在问如何只解析结果吗?没有任何 XML 解析器能够提供这个吗?
-
我一直在尝试一切,当我尝试最简单的解析器示例时,它返回未定义。不久前尝试过这个:var parser, text, xmlDoc;解析器 = 新的 DOMParser(); xmlDoc = parser.parseFromString(response, "text/xml"); console.log(xmlDoc.getElementsByTagName("ns\\:return")[0].childNodes[6].nodeValue);
-
您应该在问题的文本中显示您尝试过的内容以及任何错误消息。请参阅How to Ask。
标签: javascript soap xml-parsing sapui5