Slet ingen der kan fortælle mig hvordan jeg får den til at opdatere
i stedet for at skrive nye childs hver gang?
Morten Jorgensen wrote in dk.edb.internet.webdesign.serverside.asp:
> Hejsa!
>
> Jeg har her et lille script der skriver til en xml fil. Problemet
> er bare at den laver nye childNodes hver gang. Jeg vil gerne have
> det sådan at den kun opdatere dem i stedet for at lave nye.
> Hvordan gør jeg det i dette script?
>
> <%@ Language=JScript%>
> <%Server.ScriptTimeout=21478836%>
> <%Response.Buffer=false%>
> <%
> // 1) To check whether the user has already pressed the submit
> button
> var submit = Request.Form("submit").Count;
> if( submit > 0 ){
>
> // 2) Create the needed to variables to store data from the
> form
> var name = Request.Form("Name");
> var age = Request.Form("Age");
> var gender = Request.Form("Gender");
> var pcode = Request.Form("PostalCode");
>
> // 3) First check whether the user has entered anything or
not
> !
> var error = "";
> if ( name == "" )
> error = "Name ";
> if ( age == "" )
> error += "Age ";
> if ( pcode == "")
> error += "PostalCode ";
>
> // 4) We have found that the user didnt entered anything
> if(error!=""){
> Response.Write("<center>");
> Response.Write("<font fac=verdana size=2>");
> Response.Write("Please enter the following data:<br>");
> Response.Write("<b>");
> Response.Write(error);
> Response.Write("</b>");
> Response.Write("</font>");
> Response.Write("</center>");
> }
> else{
> // Response.Write(name+" has been added to your Friend
> list.");
> // 5) Load the xmlDoc and create the required
> elements/nodes
> var
> xmlDoc=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
> xmlDoc.async="false";
> xmlDoc.load(Server.MapPath("Person.xml"));
>
> var nodeList = xmlDoc.getElementsByTagName("PersonList");
> if(nodeList.length > 0){
> var parentNode = nodeList(0) ;
> var personNode = xmlDoc.createElement("Person");
> var nameNode = xmlDoc.createElement("Name");
> var ageNode = xmlDoc.createElement("Age");
> var genderNode = xmlDoc.createElement("Gender");
> var pcodeNode = xmlDoc.createElement("PostalCode");
>
> nameNode.text = name;
> ageNode.text = age;
> genderNode.text= gender;
> pcodeNode.text = pcode;
>
> // 6) Attach the nodes to the parent node (Person)
> parentNode.appendChild(personNode);
> personNode.appendChild(nameNode);
> personNode.appendChild(ageNode);
> personNode.appendChild(genderNode);
> personNode.appendChild(pcodeNode);
>
> // 7) Now save the nodes to the file
> xmlDoc.save(Server.MapPath("Person.xml"));
> }
> }
> }
> %>
> <html><body>
> <CENTER><p><FONT face=Verdana><U><b>Add My Friends to XML</b></U>
> </FONT> </p></CENTER>
> <form action="VerifyPerson.asp" method="post" name="frmPerson"
> id="frmPerson">
> <table border=0 align=center style="height: 184px" width="255">
> <TBODY>
> <TR><TD width="78"><FONT face=Verdana size=2>
> <P align=left>Name:</FONT></P></TD><TD width="154"><INPUT
> name=Name ><FONT
> face=Verdana size=2></FONT></TD>
> <TR><TD width="78"><FONT face=Verdana size=2>Age: </FONT>
> </TD><TD width="154"><INPUT name=Age ><FONT
> face=Verdana size=2></FONT></TD>
> <TR><TD width="78"><FONT face=Verdana
> size=2>Gender:</FONT></TD><TD width="154">
> <SELECT style="WIDTH: 154px" name=Gender>
> <OPTION value=Male selected>Male</OPTION>
> <OPTION value=Female>Female</OPTION>
> </SELECT>
> </TD>
> <TR><TD width="78"><FONT face=Verdana size=2>Postalcode: </FONT>
> </TD><TD width="154"><INPUT name=Postalcode ><FONT
> face=Verdana></FONT></TD>
> <td width="3">
> <P><FONT face=Verdana></FONT></P></TR>
> <td width="78">
> <P><FONT face=Verdana></FONT></P>
> <TR>
> <TD COLSPAN=2 width="238"><center><INPUT type=submit
> value=Submit name=submit>
> <INPUT type=reset value=Reset name=reset></center>
> </form>
> </TABLE><BR><br>
> <CENTER><FONT face=Verdana><U><b>My Friend list</b></U> </FONT>
> </CENTER><br>
> <table border="1" style="border-collapse: collapse; height:
> 20px" bordercolor=#000000 align=center bgColor=silver
> width="417">
>
> <TR><TD width="93"><FONT face=Verdana size=2>
> <STRONG style="BACKGROUND-COLOR:
> silver">Name</STRONG></FONT></TD>
> <TD width="69"><FONT face=Verdana size=2><STRONG
> style="BACKGROUND-COLOR: silver">Age</STRONG></FONT></TD>
> <TD width="112"><FONT face=Verdana size=2><STRONG
> style="BACKGROUND-COLOR: silver">Gender</STRONG></FONT></TD>
> <TD width="115"><FONT face=Verdana size=2><STRONG
> style="BACKGROUND-COLOR: silver">Postal Code</STRONG></FONT></TD>
> </TR>
> <%
> // This part is used to display the data in a table via XSL
>
> var objXMLDoc =
> Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
> objXMLDoc.async = false;
> objXMLDoc.load(Server.MapPath("person.xml"));
>
> var xsl=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
> xsl.async = false;
> xsl.load(Server.MapPath("person.xsl"));
>
> var xmlQuery="//Person";
> var
> docHeadlines=objXMLDoc.documentElement.selectNodes(xmlQuery);
>
> var numNodes;
> numNodes=docHeadlines.length;
>
> var nn;
> for(var i=0;i<numNodes;i++){
> nn = docHeadlines.nextNode();
> Response.Write(nn.transformNode(xsl));
> }
> %>
> </table>
> </body>
> </html>
>
> --
> Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
> - Pædagogiske tutorials på dansk
> - Kom godt i gang med koderne
> KLIK HER! =>
http://www.html.dk/tutorials
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials