是否可以使用jQuery xml处理程序解析SOAP响应? [英] Is it possible to parse a SOAP response with a jQuery xml handler?

查看:196
本文介绍了是否可以使用jQuery xml处理程序解析SOAP响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下SOAP响应:

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>

我的问题是,我可以用jQuery解析这个,如下面的......

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);

目前这会返回一个空白字符串 - 正确的 jQuery 调用以获得余额?

Currently this returns a blank string - what would be the correct jQuery call to get "balance"?

推荐答案

您需要使用双反斜杠转义特殊字符(冒号) \\

You need to escape special characters (the colon) using double backslashes \\

var xmlText = $(xml).find("soap\\:Envelope")
                    .find("soap\\:Body")
                    .find("getPurseBalanceResponse")
                    .find("getPurseBalanceResult")
                    .find("balance").text();
console.log(xmlText);

这是工作小提琴

这篇关于是否可以使用jQuery xml处理程序解析SOAP响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆