I created a script which loads my xml file and it also saves my xml file to a persons HD using an ActiveX plugin.
Now what I would like to do is have my script take the loaded XML file and add child elements and then save it. But I want this to be done in memory that way the user doesnt have to see it.
So here is what the load part looks like:
Code:
<script type="text/javascript">
<!--
// Loads plugins.xml
var xmlFile = './plugins.xml';
function loadXML(xmlFile) {
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.onreadystatechange = verify(xmlDoc);
xmlDoc.load(xmlFile);
xmlObj = xmlDoc.documentElement;
return xmlDoc;
}
function verify(xmlDoc) {
// 0 Object is not initialized
// 1 Loading object is loading data
// 2 Loaded object has loaded data
// 3 Data from object can be worked with
// 4 Object completely initialized
if (xmlDoc.readyState != 4) {
return false;
}
return xmlDoc;
}
function getPlugins(xmlFile) {
loadXML(xmlFile);
var pluginFiles = Array();
var nodeCount = xmlObj.childNodes.length;
for( var x = 0; x < nodeCount; x++) {
pluginFiles[x] = xmlObj.getElementsByTagName("plugin")[x].childNodes(1).text;
}
for( var x = 0; x < pluginFiles.length; x++) {
document.write(" <script type=\"text/javascript\" src=\"./plugins/" + pluginFiles[x] + "\"></script>\n");
}
return true;
}
getPlugins(xmlFile);
//-->
</script>
I imagine I should be using the 'xmlObj' I created to add child nodes but I am unsure how to do this. Anyone have any suggestions?
Once that part is complete I have a script made to save the current xmlObj to a file.
And this is my XML file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<plugins>
<plugin>
<name>Music</name>
<file>music.js</file>
</plugin>
<plugin>
<name>Weather</name>
<file>weather.js</file>
</plugin>
<plugin>
<name>Notes</name>
<file>notes.js</file>
</plugin>
</plugins>
I want to add a new 'plugin' node with its nessacary child nodes.