I am having an issue with the XML Dom
I am trying to create a simple system where a user inputs a comment which is then written to the xml file using the XML Dom. I'm not sure what my problem is, so I'll post all relevant information, thanks in advance.
XML FILE:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href=" ?>
<article_space>
<com>
<user>Seth_Bean</user>
<c_date>Today</c_date>
<c_body>Rad post brah</c_body>
</com>
<article>
<title>article1</title>
<author>Barbara</author>
<date>Today</date>
<body_text>
This is my article, hello.
</body_text>
</article>
</article_space>
Javascript function:
function addComment(form)
{
var param = '<xsl:value-of select="/article_space/article/title" />'; xmlDoc = loadXMLDoc(""+param+".xml");
<!--param is used for the title of the file to be opened-->
xmlDoc=loadXMLDoc(param+".xml");
<!--Clones the comment node and it's children-->
var root = xmlDoc.documentElement;
var curr_node = root.firstChild;
var new_node = curr_node.cloneNode(true);
root.appendChild(new_node);
<!--values from a form-->
var text = form.text.value;
var id = form.id.value;
<!--Adds text to the comment node-->
x=xmlDoc.getElementsByTagName("c_body")[0].childNodes[0];
x.nodeValue= text;
x=xmlDoc.getElementsByTagName("user")[0].childNodes[0];
x.nodeValue = id;
return true;
}
the input form:
<div id="c_input" name="c_input">
<form onsubmit="addComment(this.form)" id="input_comment" method="post">
<input id="id" type="text" />
<textarea id="text" cols="30" rows="10"/><br />
<input type="submit" value="Post Comment" />
</form>
</div>
I am trying to create a simple system where a user inputs a comment which is then written to the xml file using the XML Dom. I'm not sure what my problem is, so I'll post all relevant information, thanks in advance.
XML FILE:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href=" ?>
<article_space>
<com>
<user>Seth_Bean</user>
<c_date>Today</c_date>
<c_body>Rad post brah</c_body>
</com>
<article>
<title>article1</title>
<author>Barbara</author>
<date>Today</date>
<body_text>
This is my article, hello.
</body_text>
</article>
</article_space>
Javascript function:
function addComment(form)
{
var param = '<xsl:value-of select="/article_space/article/title" />'; xmlDoc = loadXMLDoc(""+param+".xml");
<!--param is used for the title of the file to be opened-->
xmlDoc=loadXMLDoc(param+".xml");
<!--Clones the comment node and it's children-->
var root = xmlDoc.documentElement;
var curr_node = root.firstChild;
var new_node = curr_node.cloneNode(true);
root.appendChild(new_node);
<!--values from a form-->
var text = form.text.value;
var id = form.id.value;
<!--Adds text to the comment node-->
x=xmlDoc.getElementsByTagName("c_body")[0].childNodes[0];
x.nodeValue= text;
x=xmlDoc.getElementsByTagName("user")[0].childNodes[0];
x.nodeValue = id;
return true;
}
the input form:
<div id="c_input" name="c_input">
<form onsubmit="addComment(this.form)" id="input_comment" method="post">
<input id="id" type="text" />
<textarea id="text" cols="30" rows="10"/><br />
<input type="submit" value="Post Comment" />
</form>
</div>