asp.net - XML output is incorrect -


i have form written in vb.net asp.net writes users data xml file. each time form used, new xml file generated data provided via form. problem i'm trying xml output resemble:

<personaldata>   <products>     <product>       <productid>1</productid>       <productnumber>123456</productnumber>     </product>  </products>   <customers>      <customer>         <lastname>winchester</lastname>         <firstname>sam</firstname>         <address>1234 elm rd</address>         <city>san antonio</city>         <state>texas</state>         <zipcode>76345</zipcode>       </customer>    </customers> </personaldata> 

however, end with:

<personaldata>   <products>     <product>       <productid>1</productid>       <productnumber>123456</productnumber>       <customers>         <customer>           <lastname>winchester</lastname>           <firstname>sam</firstname>           <address>1234 elm rd</address>           <city>san antonio</city>           <state>texas</state>           <zipcode>76345</zipcode>         </customer>       </customers>     </product>   </products> </personaldata> 

this code -button click-:

 public sub write_xml(byval sender system.object, byval e system.eventargs)         dim textwriter new xmltextwriter(server.mappath("xml/persondatavi.xml"), nothing)         textwriter.formatting = system.xml.formatting.indented         'start new document         textwriter.writestartdocument()         'write comment         textwriter.writecomment("this comment")         'insert start element -root element node         textwriter.writestartelement("personaldata")         'write start element         textwriter.writestartelement("products")         'write child start element         textwriter.writestartelement("product")         'write productid element , data         textwriter.writestartelement("productid", "")         textwriter.writestring(txtproductid.text)         textwriter.writeendelement()         'write productid element , data         textwriter.writestartelement("productnumber", "")         textwriter.writestring(txtproductnum.text)         textwriter.writeendelement()         'write child element         textwriter.writestartelement("customers")         'write child element         textwriter.writestartelement("customer")         'write lastname element , data         textwriter.writestartelement("lastname", "")         textwriter.writestring(txtlastname.text)         textwriter.writeendelement()         'write firstname element , data         textwriter.writestartelement("firstname", "")         textwriter.writestring(txtfirstname.text)         textwriter.writeendelement()         'write address element , data         textwriter.writestartelement("address", "")         textwriter.writestring(txtaddress.text)         textwriter.writeendelement()         'write city element , data         textwriter.writestartelement("city", "")         textwriter.writestring(txtcity.text)         textwriter.writeendelement()         'write state element , data         textwriter.writestartelement("state", "")         textwriter.writestring(txtstate.text)         textwriter.writeendelement()         'write zipcode elment , data         textwriter.writestartelement("zipcode", "")         textwriter.writestring(txtzipcode.text)         textwriter.writeendelement()         'end         textwriter.writeenddocument()         'clean         textwriter.flush()         textwriter.close()         'display xml document         response.redirect(server.mappath("xml/persondatavi.xml"))     end sub 

what doing wrong here?

you missing writeendelement product , products.

after

textwriter.writestartelement("productnumber", "") textwriter.writestring(txtproductnum.text) textwriter.writeendelement() 

you need 2 more

textwriter.writeendelement() 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -