Find xml attribute values with javascript

前端 未结 2 1644
野趣味
野趣味 2021-01-14 03:18

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

I\'m trying to get the value of the duration attribute on the node, then get the fixedValu

2条回答
  •  孤街浪徒
    2021-01-14 04:00

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

    Try using the below method

    var currentLoanRates = function() {
        var currLoanXml = '',
        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);
            }
        });
    
    };
    

提交回复
热议问题