我需要帮助将此XML格式化,以便将其放入HTML元素。
这是由软件生成的XML:
<event status="coming up">
<song title="Summer Of '69">
<artist name="Bryan Adams" id="" url="">
<info starttime="03:28:44" jazlerid="1997" playlisterid="">
<media runtime="03:27">
<songurl></songurl>
<songbarcode></songbarcode>
<songcdkey></songcdkey>
</media>
</info>
</artist>
</song>
<song title="Doing It All For My Baby">
<artist name="Huey Lewis & The News" id="" url="">
<info starttime="03:32:11" jazlerid="2312" playlisterid="">
<media runtime="03:25">
<songurl></songurl>
<songbarcode></songbarcode>
<songcdkey></songcdkey>
</media>
</info>
</artist>
</song>
<song title="Freeway Of Love">
<artist name="Aretha Franklin" id="" url="">
<info starttime="03:35:36" jazlerid="1843" playlisterid="">
<media runtime="05:44">
<songurl></songurl>
<songbarcode></songbarcode>
<songcdkey></songcdkey>
</media>
</info>
</artist>
</song>
<song title="All I Need Is A Miracle">
<artist name="Mike & The Mechanics" id="" url="">
<info starttime="03:41:21" jazlerid="2538" playlisterid="">
<media runtime="04:03">
<songurl></songurl>
<songbarcode></songbarcode>
<songcdkey></songcdkey>
</media>
</info>
</artist>
</song>
<song title="Sweet Nothing PLAY !!!!">
<artist name="Calvin Harris with Florance Welsh" id="" url="">
<info starttime="03:45:33" jazlerid="5362" playlisterid="">
<media runtime="03:26">
<songurl></songurl>
<songbarcode></songbarcode>
<songcdkey></songcdkey>
</media>
</info>
</artist>
</song>
</event>
我知道如何使用以下代码将其放入我的网页:
function loadnext()
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200)
{
document.getElementById('ntn').innerHTML = this.responseText;
}
};
xhttp.open("GET", "AirPlayNext.xml"+ ((/\?/).test("AirPlayNext.xml") ? "&" : "?") + (new Date()).getTime());
xhttp.setRequestHeader( 'CacheControl', false );
xhttp.send();
}
上面的代码获取数据并将其插入HTML标记。我还添加了一个日期例程来强制更新(这可以防止在所有浏览器中缓存xhr)
我知道如何解析一个属性,但是如何从单个xml标记中解析所有属性?