i have existing xml file want use store contents of submission form.
/**** xml file storeuserinfo.xml:
<?xml version="1.0" encoding="utf-8" ?> <recordstore> </recordstore> /****** form
<div>genre: <asp:textbox id="txtgenre" runat="server" /></div><br /> <div>title: <asp:textbox id="txttitle" runat="server" /></div><br /> <div>name: <asp:textbox id="txtname" runat="server" /></div><br /> <div>email: <asp:textbox id="txtemail" runat="server" /></div><br /> <div>comments: <br /><asp:textbox id="txtcomment" runat="server" width="200px" height="100px" /></div><br /> <div><asp:button id="btnsubmit" runat="server" text="submit" onclick="btnsubmit_click" /></div><br /> <div> <asp:label id="lblresult" runat="server" /> </div> /********** source code
//function create nodes xmlnode createbooknode(xmldocument doc) { //create author node , children xmlnode recordnode = doc.createelement("record"); xmlattribute genreattribute = doc.createattribute("genre"); genreattribute.value = txtgenre.text; recordnode.attributes.append(genreattribute); //create title attribute , add children of record node xmlnode titlenode = doc.createelement("title"); titlenode.innertext = txttitle.text; recordnode.appendchild(titlenode); //create author node , it's children xmlnode authornode = doc.createelement("author"); xmlnode fullnamenode = doc.createelement("fullname"); fullnamenode.innertext = txtname.text; authornode.appendchild(fullnamenode); //now add email xmlnode emailnode = doc.createelement("email"); emailnode.innertext = txtemail.text; authornode.appendchild(emailnode); recordnode.appendchild(authornode); //now add comments xmlnode commentnode = doc.createelement("comments"); commentnode.innertext = txtcomment.text; recordnode.appendchild(commentnode); return recordnode; } //button click protected void btnsubmit_click(object sender, eventargs e) { //path xml file string xmlpath = mappath("storeuserinfo.xml"); xmldocument doc = new xmldocument(); doc.load(xmlpath); xmlnode recordnode = createbooknode(doc); //get reference book node , append book node xmlnode recordstorenode = doc.selectsinglenode("recordstore"); recordstorenode.appendchild(recordnode); lblresult.text = "xml document has been updated"; } ... i'm not getting errors, form fails write contents of form xml file when button clicked. provides assistance i'm missing?
i got working; btnsubmit_click function missing doc.save(xmlpath);
Comments
Post a Comment