最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to parse a SOAP response with a jQuery xml handler? - Stack Overflow

programmeradmin3浏览0评论

I have the following SOAP response:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd=""xmlns:xsi="" xmlns:soap="/">
    <soap:Body>
        <getPurseBalanceResponse xmlns="/">
            <getPurseBalanceResult>
                <callStatus>
                    <Success>true</Success>
                    <ErrorCode/>
                </callStatus>
                <balance>63.35</balance>
                <pending>30</pending>
                <logoUrl>.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"?

I have the following SOAP response:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3/2001/XMLSchema"xmlns:xsi="http://www.w3/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap/soap/envelope/">
    <soap:Body>
        <getPurseBalanceResponse xmlns="https://secure.card./">
            <getPurseBalanceResult>
                <callStatus>
                    <Success>true</Success>
                    <ErrorCode/>
                </callStatus>
                <balance>63.35</balance>
                <pending>30</pending>
                <logoUrl>https://prepa.sqasddsad./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"?

Share Improve this question edited Mar 22, 2013 at 14:28 shytikov 9,5589 gold badges61 silver badges105 bronze badges asked Nov 30, 2011 at 16:26 DavidDavid 20.1k30 gold badges109 silver badges128 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

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

Here is a working fiddle.

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.

发布评论

评论列表(0)

  1. 暂无评论