473,473 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I update my xml file (existing) data using c#

1 New Member
my file is like:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?> <CarList 
  2.     xmlns="http://tempuri.org"
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.     xsi:schemaLocation="http://tempuri.org carSchema.xsd"
  5.  > 
  6. <cars car_Id="1"> 
  7. <car_make>MARUTI</car_make> 
  8. <car_model>WAGONR</car_model> 
  9. <car_year>2000</car_year> 
  10. <car_price>400000</car_price> 
  11. <reg_num>MA123</reg_num> 
  12. <prev_owner>SAMEER</prev_owner> 
  13. </cars> 
  14. <cars car_Id="2" > 
  15. <car_make>MARUTI</car_make>
  16.  <car_model>WAGONR</car_model> 
  17. <car_year>2000</car_year> 
  18. <car_price>400000</car_price> 
  19. <reg_num>MA123</reg_num> 
  20. <prev_owner>SAMEER</prev_owner> 
  21. </cars>  </CarList>
How i can update my xml file(existing) data using c#
Jan 14 '13 #1
2 2742
adriancs
122 New Member
Read the whole file.
load it into Dictionary, Class or whatever.
Modify as need.
Rewrite the whole file.
Jan 14 '13 #2
leecorp
10 New Member
This code can Access the XML File

Then Add some new Elements to it

Then Append the XML File


Expand|Select|Wrap|Line Numbers
  1. string fileName = RemoveSpecialCharacters(DateTime.Now.ToString()) + FileUpload1.FileName;
  2.         XmlWriterSettings st = new XmlWriterSettings();
  3.         st.Indent = true; ;
  4.  
  5.         st.OmitXmlDeclaration = true;
  6.         st.Encoding = Encoding.ASCII;
  7.  
  8.  
  9.         // to append to the existing files 
  10.         try
  11.         {
  12.             XElement xml = XElement.Load(Server.MapPath(".\\XML\\data.xml"));
  13.             xml.Add(new XElement("Software", new XAttribute("Name",TextBox1.Text) ));
  14.             xml.Save(Server.MapPath(".\\XML\\data.xml"));
  15.  
  16.         }
  17.         catch(Exception ex){}
  18.  


Hope this Works
Good Day
Jan 15 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new...
8
by: yinjennytam | last post by:
Hi all, I'm new to .NET and XML and I have a question. Given an XML file, I want to navigate its content and look for one or two particular elements to get their values. At this point, it...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
0
by: ramananth | last post by:
i want to update the xml data using pl/sql.can u please give me the pl/sql code for updation.
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
5
by: Edwin | last post by:
I am trying to write an application among which one of the functions is to determine the number of unique extensions found in a directory and all of its sub directories. I am trying to use Linq to...
4
ddtpmyra
by: ddtpmyra | last post by:
Im having trouble on updating the file inside mysql database using the php. Should I use <form> or im wrong on how I called the variable from previous page? FORM 1 - that accepts the file pointer...
0
by: kumardharanik | last post by:
Hi Friends, The below code is a sample code for insert, update and delete using datagrid but i need to convert the entire code for datagridview.. Plsss help me.. using System; using...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.