如何在javascript中循环遍历XML节点

时间:2017-03-23 11:33:00

标签: javascript xml

如何循环使用以便获取每个节点的值。

我必须在div HTML TAG中显示每个节点的值

请找到以下XML。

  <!-- CODE--> 

<RESULT>
    <PARM ID="1">
        <DATA NAME="SMARTPHONEDETAILS">
            <ROW ID="1">
                <SMARTPHONEDETAILS ID="1">
                    <ELEMENT NAME="PHONE_MODEL">Apple iPhone 5S
                    </ELEMENT>
                    <ELEMENT NAME="T_phone">3</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">99.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">99.99</ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">16GB</ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">16GB</ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
            <ROW ID="2">
                <SMARTPHONEDETAILS ID="2">
                    <ELEMENT NAME="PHONE_MODEL">Apple iPhone 6</ELEMENT>
                    <ELEMENT NAME="T_phone">4</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">199.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">99.99</ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">16GB</ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">64GB
                    </ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
            <ROW ID="3">
                <SMARTPHONEDETAILS ID="3">
                    <ELEMENT NAME="PHONE_MODEL">Apple iPhone 6 Plus</ELEMENT>
                    <ELEMENT NAME="T_phone">6</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">199.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">299.99</ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">
                        16GB
                    </ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">64GB</ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
            <ROW ID="4">
                <SMARTPHONEDETAILS ID="4">
                    <ELEMENT NAME="PHONE_MODEL">Apple iPhone 6S</ELEMENT>
                    <ELEMENT NAME="T_phone">8</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">199.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">
                        299.99
                    </ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">16GB</ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">64GB</ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
            <ROW ID="5">
                <SMARTPHONEDETAILS ID="5">
                    <ELEMENT NAME="PHONE_MODEL">Apple iPhone 6S Plus</ELEMENT>
                    <ELEMENT NAME="T_phone">8</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">299.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">399.99</ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">16GB</ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">
                        64GB
                    </ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
            <ROW ID="6">
                <SMARTPHONEDETAILS ID="6">
                    <ELEMENT NAME="PHONE_MODEL">Samsung Galaxy Note 4
                    </ELEMENT>
                    <ELEMENT NAME="T_phone">1</ELEMENT>
                    <ELEMENT NAME="MIN_PRICE">229.99</ELEMENT>
                    <ELEMENT NAME="MAX_PRICE">229.99</ELEMENT>
                    <ELEMENT NAME="MIN_CAPACITY">32GB</ELEMENT>
                    <ELEMENT NAME="MAX_CAPACITY">32GB</ELEMENT>
                </SMARTPHONEDETAILS>
            </ROW>
        </DATA>
    </PARM>
</RESULT>

请您告诉我,我可以在java脚本或j查询中执行此操作

0 个答案:

没有答案