I have an HTML page in local, with one of its pages that contains a form that has to modify an XML file that is part of the project. The file is part of the page, not the machine that was a client. The XML should be recorded as a file, not as a sample of how it is left.
HTML form:
<form>
Titulo: <input type="text" name="titulo" id="titulo"><br />
Descripcion: <input type="text" name="desc" id="desc"><br />
Agregar imagen: <select id="seleccion">
<option onclick='hide()' value="A" selected="selected">No</option>
<option onclick='unhide()' value="b">Sí</option>
</select>
<input type="file" class='hidden' id='imag' accept="image/*"/><br />
<button type="reset" onclick='hide()'>Reiniciar campos</button> <button type="button" onclick="enviar()">Enviar</button>
</form>
In sending, I have the following code in JS
function enviar()
{
var titulo=document.getElementById("titulo").value;
var desc=document.getElementById("desc").value;
var e=document.getElementById("seleccion");
var img;
if (e.options[e.selectedIndex].value=="b")
img=recuperar_nombre(); //No va
else
img="a";
if (titulo==null||titulo=="")
alert("Rellene el título")
else
if (desc==null|| desc=="")
alert("Rellene la descripción")
else
if (img=="")
alert("Desmarque la subida de archivos")
else
grabar_xml(titulo,desc,img); //Esto es en lo que pido ayuda. Sería abrir el fichero para escritura, saltarse el elemento raíz, escribir, guardar, y salir, sin mostrar
}
The XML, if needed:
<articulos>
<articulo>
<article>
<h2>TEST</h2>
<p></p>
</article>
<img href=''></img>
</articulo>
<articulo>
<article>
<h2>prueba</h2>
<p></p>
</article>
<img href=''></img>
</articulo>