一个test.xml中,有一对值,这对值是“百度”“www.baidu.com”
做一个test.html。
双击打开这个html,它就会读取这个test.xml中的值,显示“百度”,而且超级连接是“www.baidu.com”。
不知道这个怎么做。
做一个test.html。
双击打开这个html,它就会读取这个test.xml中的值,显示“百度”,而且超级连接是“www.baidu.com”。
不知道这个怎么做。
解决方案 »
- 做个调查,大家现在都在用什么框架?来着有分!谢谢参与!
- struts2怎么取得实际地址?
- 写了2个actionForm 这个LoginForm中uid接收到了,uName和uPass老接收不到。。。
- can bind a LONG value only for insert into a LONG column
- 谁有myeclipse6.0 for linux啊?
- 求各位大虾帮忙!
- 如果session里面不存在关键字key1,能不能取出对象来?
- 大家救救我,我连写if then 都出错!!
- 请问:用ASP开发的网站,现要用JSP开发网站内的购物车系统,好实施吗?
- 用SmartUpload做下载程序时,总是报如下错误,为什么?
- 有这样一个网站如何设计?
- jsp中while(rs.next())问题
你把xml文件写出来看看
Properties p = new Properties();
p.setProperty("teacher", "com.highcom.service.impl.TeacherImpl");
p.setProperty("child", "com.highcom.service.impl.ChildImpl");
//写properties文件 也可以写xml文件 需要jdk 1.5
p.store(new FileOutputStream("common.pro"), "highcom-->pro");
// 第一种方法加载properties 文件 可读取xml文件
p.load(new FileInputStream("src\\common.properties"));
p.loadFromXML(new FileInputStream("lxh.xml")) ;
System.out.println(p.getProperty("teacher"));
System.out.println("-----------------------------------");
//第二种方法加载properties文件
ResourceBundle rs = ResourceBundle.getBundle("common");
PersonInterface person = null;
person = (PersonInterface)
Class.forName(rs.getString("teacher")).newInstance();
person.work();
person.city(); String pro = InputStream.in();
Main m = new Main();
PersonInterface pf = (PersonInterface) m.instance(pro);
pf.work();
pf.city(); } public Object instance(String pro) {
ResourceBundle rs = ResourceBundle.getBundle("common");
Object obj = null;
obj = Class.forName(rs.getString(pro)).newInstance();
return obj;
}
}自己以前用过的代码,可读写properties和xml,读写xml需要jdk1.5以上。
var doc = new ActiveXObject("Msxml2.DOMDocument");
doc.selectSingleNode("//AAA[@id='"+a+"']");
随便找个JS框架,jquery.js/prototype.js都行
几句代码就搞定了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<XML ID="xmldata" SRC="test.xml"></XML>
<table width="200" border="1" datasrc="#xmldata" >
<tr>
<td><a href="" id = "c"><span DATAFLD="name"></a></td>
</tr>
</table>
<p> </p>
<p>
<script language="javascript">
dom = new ActiveXObject("Microsoft.XMLDOM");
dom.async = false;
dom.load("test.xml"); //加载xml文件
// window.alert('IE');
node = dom.documentElement.childNodes;
//alert(node);
var title = node[0].childNodes[1].text;
// data.push({title:title});
document.getElementById("c").href=title;
</script>
</p>
</body>
</html><?xml version="1.0" encoding="gb2312"?>
<links>
<link id="01">
<name>百度</name>
<address>http://www.baidu.com</address>
</link>
</links>
不知道是不是你想要的效果!
不知道内容别人怎么给写代码呀?
给一个通用的例了给你,是用java的jdom做的
public class Son implements Operation_xml{
public static String xmlfile = null;
public static String son = null;
public static String grandson = null;
public static String value= null;
public static Vector ve = new Vector();// 查询的值放入此向量中
public Son() {
// TODO Auto-generated constructor stub
}
public void creat() {
// TODO Auto-generated method stub
}
public void delete() {
// TODO Auto-generated method stub
FileInputStream fi = null; // 文件输入流
FileOutputStream fo = null; // 文件输出流
try {
fi = new FileInputStream(new File(xmlfile));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(fi);// 把文件流给build
Element root = doc.getRootElement();// 得到根元素
List childsum = root.getChildren();// 得到根元素的集合
Element son_elem = root.getChild(son); // 获取一级标签
root.removeContent(root.getChild(son));
// System.out.println(grson_elem.getContentSize());
// for (int i = 0; i < grson_elem.getContentSize(); i++) { // 将一级标签下的子标签转为向量类型
//
// System.out.println("###"+grson_elem.getContent(i).getValue()+"###");
// }
//
// Element namechildsum = root.getChild(childelement); // 获取指定的一级标签
// for (int i = 0; i < namechildsum.getContentSize(); i++) { // 遍历这个一级标签
//
// if (namechildsum.getContent(i).getValue().equalsIgnoreCase(
// editby)) {// 找出被修改的二级标签
// // System.out.println("edit="+namechildsum.getContent(i).
// // getValue());
// Element towchild = (Element) namechildsum.getContent(i);// 选中这个二级元素
// namechildsum.removeContent(namechildsum.getContent(i));// 删除
// System.out.println("towchild="+towchild.getName());
// }
// }
XMLOutputter xmlOut = new XMLOutputter();
Format format = xmlOut.getFormat();
format.setExpandEmptyElements(true); // 是否填
xmlOut.setFormat(format);
fo = new FileOutputStream(new File(xmlfile));// 写入文件
xmlOut.output(doc, fo);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fi.close();
fo.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void edit() {
// TODO Auto-generated method stub
FileInputStream fi = null; // 文件输入流
FileOutputStream fo = null; // 文件输出流
try {
fi = new FileInputStream(new File(xmlfile));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(fi);// 把文件流给build
Element root = doc.getRootElement();// 得到根元素
Element son_elem = root.getChild(son); // 获取指定的一级标签
// Element grson_elem = (Element) son_elem.getChild(grandson);// 选中这个二级元素
// Element grgrson_elem = (Element) grson_elem.getChild(great_grandson);// 选中这个三级元素
// grson_elem.setText(value);// 设置新值
son_elem.setName(value);
XMLOutputter xmlOut = new XMLOutputter();
Format format = xmlOut.getFormat();
format.setExpandEmptyElements(true); // 是否填
xmlOut.setFormat(format);
fo = new FileOutputStream(xmlfile);// 写入文件
xmlOut.output(doc, fo);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fi.close();
fo.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void list() {
// TODO Auto-generated method stub
FileInputStream fi = null; // 文件输入流
ve = new Vector();
try {
fi = new FileInputStream(new File(xmlfile));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(fi);// 把文件流给build
Element root = doc.getRootElement();// 得到根元素
List childsum = root.getChildren();// 得到根元素的集合
for (int i = 0; i < root.getContentSize(); i++) { // 将一级标签下的子标签转为向量类型
Vector vec = new Vector();
vec.addElement(i);
Element son_elem =(Element)root.getContent(i); // 获取一级标签
vec.addElement(son_elem.getName());
ve.addElement(vec);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 建立打开流
catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fi.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void search() {
// TODO Auto-generated method stub
}
public void add() {
// TODO Auto-generated method stub
FileInputStream fi = null; // 文件输入流
FileOutputStream fo = null; // 文件输出流
try {
fi = new FileInputStream(new File(xmlfile));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(fi); // 把文件流给build
Element root = doc.getRootElement(); // 得到根元素
List childsum = root.getChildren(); // 得到根元素的集合
Element son_elem = new Element(son); // 获取指定的一级标签
// Element grson_elem = (Element) son_elem.getChild(grandson);// 选中这个二级元素
// Element namechildsum = root.getChild(childelement); // 获取一级标签
// Element newcount = new Element(sub_childelement); // 生成新元素(二级标签)
// Element grson_elem = new Element(grandson); // 生成新元素(二级标签)
// newcount.setText(sub_childelement_txt); // 设置标签内容
// grson_elem.setText(value);
root.addContent(son_elem); // 在新根下添加新元素
ve.addElement(son_elem.getName());
XMLOutputter xmlOut = new XMLOutputter();
Format format = xmlOut.getFormat(); // 把输出流格式化
format.setExpandEmptyElements(true); // 是否填充
// format.setIndent(""); // 设置分割符
xmlOut.setFormat(format); // 把格式化的流给输出流
fo = new FileOutputStream(xmlfile);
xmlOut.output(doc, fo); // 把内容添加到文件
System.out.println("添加成功");
fi.close(); // 关闭输入流
fo.close(); // 关闭输出流
} catch (FileNotFoundException e) { e.printStackTrace();
} catch (JDOMException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
}
}