久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 javascript 查找 xml 屬性值

Find xml attribute values with javascript(使用 javascript 查找 xml 屬性值)
本文介紹了使用 javascript 查找 xml 屬性值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何使用 Javascript/jQuery 獲取 XML 節點的屬性值?

How do I get the attribute value of an XML node with Javascript / jQuery?

我正在嘗試獲取節點上duration屬性的值,然后獲取fixedValue.

I'm trying to get the value of the duration attribute on the node, then get the fixedValue.

<loanAmount>
    <interestRates>
        <interestRate allowInterestOnly="true" type="variable" value="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="1" fixedInterestOnlyValue="5.7" fixedValue="5.7" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="3" fixedInterestOnlyValue="5.75" fixedValue="5.75" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="5" fixedInterestOnlyValue="6.64" fixedValue="6.56" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="10" variableInterestOnlyValue="5.82"/>
    </interestRates>
</loanAmount>'

到目前為止,我得到了:

So far I've got:

var currentLoanRates = function() {
    var currLoanXml = '<loanAmount><interestRates><interestRate allowInterestOnly="true" type="variable" value="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="1" fixedInterestOnlyValue="5.7" fixedValue="5.7" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="3" fixedInterestOnlyValue="5.75" fixedValue="5.75" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="5" fixedInterestOnlyValue="6.64" fixedValue="6.56" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="10" variableInterestOnlyValue="5.82"/></interestRates></loanAmount>',
    xmlDoc = $.parseXML( currLoanXml ),
    $xml = $( xmlDoc ),
    $intRate = $xml.find("interestRate"),
    $varIntRate = $intRate.attr("fixedValue");

    console.log($intRate);
    console.log($varIntRate);
};

第二個 console.log 打印 undefined.

The second console.log prints undefined.

推薦答案

我遇到的第一個問題是 currLoadXml 不是字符串.它需要用單引號括起來.

The first problem I ran into is that currLoadXml is not a string. It needs to be wrapped inside single quotes.

試試下面的方法

var currentLoanRates = function() {
    var currLoanXml = '<loanAmount><interestRates><interestRate allowInterestOnly="true" type="variable" value="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="1" fixedInterestOnlyValue="5.7" fixedValue="5.7" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="3" fixedInterestOnlyValue="5.75" fixedValue="5.75" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="5" fixedInterestOnlyValue="6.64" fixedValue="6.56" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="10" variableInterestOnlyValue="5.82"/></interestRates></loanAmount>',
    xmlDoc = $.parseXML( currLoanXml ),
    $xml = $( xmlDoc ),
    $intRate = $xml.find("interestRate");
    $intRate.each(function(index, element) { 
        if(element.attributes["duration"]) {
            console.log("Duration :" + element.attributes["duration"].value);
        }

        if(element.attributes["fixedValue"]) {
            console.log("Fixed value:" + element.attributes["fixedValue"].value);
        }
    });

};

這篇關于使用 javascript 查找 xml 屬性值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 99色综合 | 国产精品永久久久久 | 亚洲精品国产电影 | 91久久北条麻妃一区二区三区 | 欧美精品一区二区三区在线播放 | 在线一区二区三区 | 久久久久成人精品免费播放动漫 | 欧美精品一区三区 | 日韩av一区二区在线观看 | 日韩在线精品 | 又黑又粗又长的欧美一区 | 精品视频在线观看 | 在线成人 | 日本污视频 | 亚洲一区二区三区在线 | 天天天堂 | 久久久.com| 精品视频 免费 | 在线一区视频 | 麻豆精品国产免费 | 伊人久久麻豆 | 成人久草| h片在线看| 欧美在线观看一区 | 久久精品一区二区三区四区 | 亚洲一区二区三区在线视频 | 日韩高清中文字幕 | 精品国产91乱码一区二区三区 | 天堂成人国产精品一区 | 欧美视频一级 | 三区在线观看 | 日韩网站在线观看 | av日韩高清 | 久久伊人一区 | 请别相信他免费喜剧电影在线观看 | 精品国产欧美 | 性高湖久久久久久久久aaaaa | 久草视频观看 | 欧美日韩精品久久久免费观看 | 殴美成人在线视频 | 欧美一区二区三区日韩 |