怎么用JS在XML中插入数据
我的xml
<?xml version="1.0" encoding="utf-8"?>
<photos>
<photo desc="01" url="_pics/bilde1.jpg" />
<photo desc="02" url="_pics/bilde2.jpg" />
</photos>
下面的JS
<script type="text/javascript">
loadXML = function(xmlFile)
{
var xmlDoc;
if(window.ActiveXObject)
{
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load(xmlFile);
}
else if (document.implementation&&document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument('', '', null);
xmlDoc.load(xmlFile);
}
else
{
return null;
}
return xmlDoc;
}
checkXMLDocObj = function(xmlFile)
{
var xmlDoc = loadXML(xmlFile);
if(xmlDoc==null)
{
alert('您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!');
window.location.href='/Index.aspx';
}
return xmlDoc;
}
var xmlDoc = checkXMLDocObj(D:\ylbdemo\photos.xml);
var newnode = doc.createNode(1,"photo","");
var v = xmlDoc.createAttribute("url");
v1.value="_pics/bilde2.jpg";
newnode.setAttributeNode(v);
</script>
tomcat打开页面就一直是白色的
------解决方案--------------------
http://www.php100.com/html/webkaifa/javascript/2010/0529/4615.html