xml文件内容如下:
并显示在jsp文件中
方法是:
一般首先jdom。可以到下载。
解析楼主XML简单代码
import java.io.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import java.util.*;
public class Test2 {
public Test2() {
}
public void readXML(){
try{
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new FileInputStream("my.xml"));
Element el = doc.getRootElement();
List ls = el.getChildren("blog_url");
Iterator it = ls.iterator();
while (it.hasNext()) {
Element sub_e = (Element) it.next();
Element sub_e_2 = sub_e.getChild("url_name");
System.err.println(sub_e_2.getName()+" "+sub_e_2.getText());
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
Test2 test2 = new Test2();
test2.readXML();
}
}
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("note.xml");
document.getElementById("1").innerHTML=xmlDoc.documentElement.nodeName //输出根节点
x=xmlDoc.documentElement.childNodes;
for (i=0;i
if (x[i].nodeType==1)
{//Process only element nodes (type 1)
document.getElementById("2").innerHTML=x[i].nodeName //输出子节点
}
}
document.getElementById("id").innerHTML=
xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
document.getElementById("photo").innerHTML=
xmlDoc.getElementsByTagName("photo")[0].childNodes[0].nodeValue;
document.getElementById("mmtitle").innerHTML=
xmlDoc.getElementsByTagName("mmtitle")[0].childNodes[0].nodeValue;
document.getElementById("tvname").innerHTML=
xmlDoc.getElementsByTagName("tvname")[0].childNodes[0].nodeValue;
document.getElementById("detail").innerHTML=
xmlDoc.getElementsByTagName("detail")[0].childNodes[0].nodeValue;
document.getElementById("adurl").innerHTML=
xmlDoc.getElementsByTagName("adurl")[0].childNodes[0].nodeValue;
}
:
id :
photo:
mtitle:
tvname:
detail:
adurl:
xml note files:
把1.0 加入 encoding="gbk" 就行了