所以我需要帮助,我有这段代码来编辑 XML 文件,但它不断拉出一个名为“DOMDocument 未定义”的错误。
第一个问题:这个错误是什么意思?
第二个问题:有办法解决吗?
这是代码;
function starter ()
{
var user = new Array();
user[0] = {'woodres' : document.getElementById("wood").innerHTML};
user[1] = {'stoneres' : document.getElementById("stone").innerHTML};
user[2] = {'steelres' : document.getElementById("steel").innerHTML};
var doc = new DOMDocument();
doc.formatOutput = true;
var r = doc.createElement("user");
doc.appendChild(r);
for (var resourceKey in user)
{
var resource = user[resourceKey];
var b = doc.createElement("resource");
var reswood = doc.createElement("reswood");
reswood.appendChild(doc.createTextNode(resource['reswood']));
b.appendChild(reswood);
var resstone = doc.createElement("resstone");
resstone.appendChild(doc.createTextNode(resource['resstone']));
b.appendChild(resstone);
var ressteel = doc.createElement("ressteel");
ressteel.appendChild(doc.createTextNode(resource['ressteel']));
b.appendChild(ressteel);
}
r.appendChild(b);
var userlogin = _SESSION['username'];
var where=simplexml_load_file('data/' + "" + userlogin + "" + '/' + "" + userlogin + "" + '.xml');
alert( doc.saveXML());
doc.save(where)
}