如何将html标签添加到xml元素

时间:2013-06-19 14:56:06

标签: xml http xml-parsing xmlhttprequest

我只是从w3学校学习XML到Html。我成功地获得了2个标签并将其作为文本发布在html上。其中一个是形象。

这次我想学习如何用图像链接标记标签并预览它?

这是xml文件

<?xml version="1.0" encoding="UTF-8"?>
<xml><version>1.0</version>
<serverid>VuXmlServer</serverid>
<page>
<templateid>vuxml:detail.xml</templateid>
<title>Lagaan</title>
<topleft_logo></topleft_logo>
<topright_logo></topright_logo>
<absurl></absurl>
</page><downloadinfo>
<name>Lagaan</name>
<ca>VuXML_PARTNER</ca>
<uniqid>ID_1</uniqid>
<mastertype>webstream</mastertype>
<type>webstream</type>
<downloadtype>Buy</downloadtype>
<duration>12916</duration>
<cost>FREE</cost><filesize>
</filesize><bitrate></bitrate>
<link>http://somelinktothevidesite.com/1.html</link>
<albumart>http://guangzhou.cust.footprint.net/JemMovies/HindiMid/Posters/Lagaan.png</albumart>
<sinfo1>Aamir Khan, Gracy Singh, Rachel Shelley</sinfo1>
<sinfo2>Hindi</sinfo2>
<sinfo3></sinfo3>
<sinfo4></sinfo4>
<linfo>too long </linfo>
<description>tool long</description></downloadinfo>
<buttons><button><name>Watch Now</name>
<link>vuxml://play</link></button>
<button><name>Page up</name>
<link>vuxml://pageup</link></button>
<button><name>Page down</name>
<link>vuxml://pagedown</link></button>
<button><name>Cancel</name>
<link>vuxml://back</link></button></buttons></xml>

这是html代码

<!DOCTYPE html>
<html>
<body>

<script>
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","1059.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("downloadinfo");
for (i=0;i<x.length;i++)
  { 
  document.write("<tr><td>");
  document.write(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("albumart")[0].childNodes[0].nodeValue);
  document.write("</td></tr>");
  }
document.write("</table>");
</script>

</body>
</html>

代码尝试添加到xml ,因此它将在html上打印图像

<img border="0" src="***LINK FROM XML***" alt="MOVIE" width="304" height="228">

0 个答案:

没有答案
相关问题