![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Writing XML [Thread Next] Re: Writing XMLTo: NULL Date: 6/2/2006 10:02:00 PM
"Jim" <jim1234@h...> wrote in message
news:83Zfg.1301$uP.1149@n......
> Hi folks,
>
> Could anyone help me with this one?
>
> I want to put something on my website were people can leave their email
> address to sign up for our newsletter. I've tried using JScript that
writes
> to an xml file.
>
> When you click on 'enter' you are redirected to the 'done.html'. I've set
> write permissions to the xml file but it doesn't seem to be working, can
> anyone see what I'm doing wrong?
>
>
>
> add.html
> ---------
> <html>
> <body>
> <form name="add_email" method="post" action="add.asp">
> <table>
> <tr>
> <td><p>Enter email</p></td>
> <td><input type="text" name="email" id="email"></td>
> <td><input type="submit" name="submit" value="enter"></td>
> </tr>
> </table>
> </form>
> </body>
> </html>
>
>
>
> add.asp
> --------
> <%@ Language=JScript%>
>
> <%
>
> var email = Request.Form("email")
>
> var xmlDoc=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
Do you need a FreeThreaded DOM??
use MSXML2.DOMDocument.3.0
> xmlDoc.async="false";
I'm not sure what will be coercing the string to "false" to a boolean but if
Javascript does it it will coerce to to true which is not what you intend
use:-
xmlDoc.async = false
> xmlDoc.load(Server.MapPath("/test/email_address.xml"));
>
> var nodeList = xmlDoc.getElementsByTagName("address");
>
> if(nodeList.length > 0){
>
Don't understand this the XML document must have a top-level element which
looks like it will be address so length will be 1.
var addressNode = xmlDoc.documentElement
Unless your XML file is more extensive than the example given and the
address node you whish to add is elsewhere.
var addressNode = xmlDoc.documentElement.selectSingleNode("address")
If (!addressNode) addressNode =
xmlDoc.documentElement.appendChild(xmlDoc.createElement("address")
The above assumes that address node is a direct child of the root node in
your xml.
> var parentNode = nodeList(0);
Hmm.. What node name will the parentNode have according to your code it will
already be an element called 'address'.
> var addressNode = xmlDoc.createElement("address");
> var emailNode = xmlDoc.createElement("email");
>
> addressNode.text = address;
Where does the address variable come from and what is it's value.
> emailNode.text = email;
>
> parentNode.appendChild(addressNode);
Adding address to address here?
> addressNode.appendChild(emailNode);
>
> xmlDoc.save(Server.MapPath("/test/email_address.xml"));
>
> }
>
> Response.Redirect("done.html")
>
> %>
I suspect you wanted something like this:-
<%@ Language=JScript%>
<%
var email = Request.Form("email")
var xmlDoc=Server.CreateObject("MSXML2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load(Server.MapPath("/test/email_address.xml"));
var addressNode = xmlDoc.documentElement
var emailNode = addressNode.appendChild(xmlDoc.createElement("email"))'
emailNode.text = email;
xmlDoc.save(Server.MapPath("/test/email_address.xml"));
Response.Redirect("done.html")
%>
Of course now what do you do if two people try to submit their email address
at the same time??
A better solution in this case would be to have the each submission create
its own file in a folder.
Have your newsletter sending system consolidate the xml and eliminate
duplicates.
>
> email_address.xml
> -------------------
> <address>
> <email>a@b...</email>
> <email>c@d...</email>
> <email>c@d...</email>
> </address>
>
>
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
