是否可以使用 jQuery xml 处理程序解析 SOAP 响应?
我有以下 SOAP 响应:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getPurseBalanceResponse xmlns="https://secure.card.com/">
<getPurseBalanceResult>
<callStatus>
<Success>true</Success>
<ErrorCode/>
</callStatus>
<balance>63.35</balance>
<pending>30</pending>
<logoUrl>https://prepa.sqasddsad.com/ytm/images/logos/sq_cashlesscaterpurse3.gif</logoUrl>
<purseId>23456</purseId>
<CurrencyCode>GBP</CurrencyCode>
</getPurseBalanceResult>
</getPurseBalanceResponse>
</soap:Body>
</soap:Envelope>
我的问题是,我可以使用 jQuery 解析它,如下所示...
var xmlText = $(xml).find("soap:Envelope").
find("soap:Body").
find("getPurseBalanceResponse").
find("getPurseBalanceResult").
find("balance").text();
console.log(xmlText);
目前这会返回一个空字符串 - 获得“余额”的正确 jQuery
调用是什么?
I have the following SOAP response:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getPurseBalanceResponse xmlns="https://secure.card.com/">
<getPurseBalanceResult>
<callStatus>
<Success>true</Success>
<ErrorCode/>
</callStatus>
<balance>63.35</balance>
<pending>30</pending>
<logoUrl>https://prepa.sqasddsad.com/ytm/images/logos/sq_cashlesscaterpurse3.gif</logoUrl>
<purseId>23456</purseId>
<CurrencyCode>GBP</CurrencyCode>
</getPurseBalanceResult>
</getPurseBalanceResponse>
</soap:Body>
</soap:Envelope>
My question is, can I parse this with jQuery such as below...
var xmlText = $(xml).find("soap:Envelope").
find("soap:Body").
find("getPurseBalanceResponse").
find("getPurseBalanceResult").
find("balance").text();
console.log(xmlText);
Currently this returns a blank string - what would be the correct jQuery
call to get "balance"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用双反斜杠转义特殊字符(冒号)
\\
这是一个 工作小提琴。
You need to escape special characters (the colon) using double backslashes
\\
Here is a working fiddle.
简短的回答:是的。 SOAP 是 XML。任何 XML 解析器都可以读取它。 SOAP 使用 XML 作为底层数据交换格式提供了一整层的东西,但如果您对使用 SOAP 库不感兴趣,XML 库将为您做这件事。只会为您带来更多工作。
Short answer: yes. SOAP is XML. Any XML parser can read it. SOAP provides a whole layer of stuff using XML as the underlying data exchange format, but if you're not interested in using a SOAP library, an XML library will do it for you. Just makes more work for you.