Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 20th, 2009, 12:59 PM
Authorized User
 
Join Date: Feb 2007
Location: Delhi, Delhi, India.
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Overwrite the User Input in XML file

Hi
I'm learning to code in C#. I'm writing the code which gets the UserInput from Command line and saves it in the XML file. I'm using XML serialization and Deserialization to get the User input(for e.g. BankAccountNumber,Type,Balance) in XML file. My code overwrites the last user input and doesn't add/increment the last user input as next entry. I guess, I'm missing some enhancement in my code to save/increment each user input in XML file. I would appreciate, If someone could help me to resolve this issue.

Thanks for Your Help !

Thanks gbianchi and samjudson for your attention and Help ! Please let me know, If you need more information.

Regards

Following is the small section of my Code :-

AccNum.accNum = number;
AccNum.accTyp = acc_typ;
AccNum.accBal = acc_balance;

// Serialize - Account(Number,Type,Balance)
// Account Number Serialization
StreamWriter acnw = newStreamWriter(@"c:\Acclist.xml");
XmlSerializer acns = newXmlSerializer(typeof(AccountBook));
acns.Serialize(acnw, AccNum);
acnw.Close();

// DeSerialize - Account(Number,Type,Balance)
// Account Number Deserialization
AccountBook acc_Number;
TextReader acnd = newStreamReader(@"c:\Acclist.xml");
acc_Number = (
AccountBook)acns.Deserialize(acnd);
acnd.Close();

return created;
  #2 (permalink)  
Old August 20th, 2009, 01:42 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Well, you are serealizing always on the same file, and only one object..

you need to probably deserialize the file first, has a "collection" of the objects containing there, add the new object (the new account), and serialize again.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
shailesh_kumar (August 20th, 2009)
  #3 (permalink)  
Old August 26th, 2009, 11:22 PM
Authorized User
 
Join Date: Feb 2007
Location: Delhi, Delhi, India.
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default The User Input in XML File

Hi Gbianchi,
Thanks for your reply. What I understand from your input is, I have to create a 'new object' each time, I serialize and deserialize a user input. In C#, Can't we have only one object do serialize and deserialize each time a User input is received. I'm sorry, I am not getting a clear picture about this implementation. Could you please elaborate more ?

Thanks for your Help !

Regards..
  #4 (permalink)  
Old August 27th, 2009, 06:43 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You are reading a single object to and from the XML file, therefore the file is only ever going to contain 1 object.

You either need to make to 1 object you are reading and writing a collection (e.g. List<AccNum>), or manually manipulate the XML using XmlDocument or some such.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
  #5 (permalink)  
Old August 27th, 2009, 12:43 PM
Authorized User
 
Join Date: Feb 2007
Location: Delhi, Delhi, India.
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for your response, samjudson.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
Overwrite user page setup for printing peter2004 CSS Cascading Style Sheets 8 December 17th, 2007 05:51 PM
How to ignore namespaces in input xml file hanifa XSLT 2 February 14th, 2007 04:14 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
write info from user input into a text file pkdev Classic ASP Components 1 September 20th, 2003 01:59 PM



All times are GMT -4. The time now is 12:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.