How to Input a Form to Change an XML File
- 1). Right-click the HTML file you want to use to edit the XML document. Click "Open With," then click the editor you use to create the HTML documents.
- 2). Create the form button that runs the JavaScript code. Add the following HTML code to your form:
<input type="submit" onclick "xmledit()" value="Click to Edit the XML" /> - 3). Create the JavaScript function that edits the XML document. You must first create the function declaration. Add the following code to create the declaration:
function xmledit() {
}
Place the XML editing code within the curly brackets. - 4). Open the XML document. You must open the XML file and assign the file to a file handler. The following code opens the XML document:
var doc = new XMLWriter("c:\file.xml");
Change the "file.xml" file with your own XML file that you want to edit. - 5). Edit the XML in the document. For instance, the following code adds a new customer to the list of customers in the XML document:
doc.BeginNode("customer");
doc.Node("customername", "Joe Smith");
doc.EndNode(); - 6). Close the file, which you must do after you finish editing the values. The following code closes the file:
doc.Close();