如何通过此xml文件获取数据?

时间:2011-07-10 11:23:48

标签: javascript html xml

<code>

<?xml version="1.0" encoding="iso-8859-1" ?>
<projects>

<project>
    <flag>1</flag>
    <name>Project 1</name>
    <descp> Short description. </descp>
    <rating> 6 </rating>
    <link> URL1 </link>
    </project>

<project>
    <flag>1</flag>
    <name>Project 2</name>
    <descp> Short description. </descp>
    <rating> 9 </rating>
    <link> URL2 </link>
    </project>

<project>
    <flag>1</flag>
    <name>Project 3</name>
    <descp> Short description. </descp>
    <rating> 4 </rating>
    <link> URL3 </link>
    </project>

<project>
    <flag>1</flag>
    <name>Project 4</name>
    <descp> Short description. </descp>
    <rating> 5 </rating>
    <link> URL4 </link>
    </project>

</projects>

</code>

我是javascript的新手,在使用getElementsbyTagName(“project”)之后我遇到了问题,我得到了一系列项目标签。但现在我很困惑如何访问子标签以从这个XML获取我需要的数据?

1 个答案:

答案 0 :(得分:0)

这里有一个使用JavaScript的XML入门指南http://www.w3schools.com/xml/xml_parser.asp