Hi
Reading in XML file using C#, changing elements and saving back to the
file, how can i do that ? I want to be able to read an XML file and
read out Elements. for example
<name>Tom</tom>
When I read from a file i want to save the XML document in memory of
the computer and when i am finished flush it back to the file, that
means i want to be able to access the element in memory of the
computer and when i change it will write it back with new changes.
What is the Best way to do that ?
I have tried it wiht xmlReader and xmlWrite, this is not saved in the
computer. 6 15467
Hi
When you want to read the XML file to memory, use:
XmlDataDocument myDoc = new XmlDataDocument ();
myDoc.Load( <filename>);
Then work with the DataDoc as normal to manipulate your data.
When you want to save the File back to the HDD, use normal File I/O to
overwrite your existing file. Get the file's contents from the
XmlDataDocument 's OuterXml property...
HTH
Cobus Lombard
Application Developer
Mint Net
South Africa
"Gerald Maher" <ge**********@w aytohere.com> wrote in message
news:d0******** *************** ***@posting.goo gle.com... Hi
Reading in XML file using C#, changing elements and saving back to the file, how can i do that ? I want to be able to read an XML file and read out Elements. for example
<name>Tom</tom>
When I read from a file i want to save the XML document in memory of the computer and when i am finished flush it back to the file, that means i want to be able to access the element in memory of the computer and when i change it will write it back with new changes.
What is the Best way to do that ? I have tried it wiht xmlReader and xmlWrite, this is not saved in the computer.
Hey,
I would just use a standard XmlDocument to do what your looking to do:
XmlDocument myDoc = new XmlDocument();
myDoc.Load(myfi le.xml);
myDoc.SelectSin gleNode("//username[@id=2]/username").Valu e = "myfirstpasswor d";
myDoc.Save(myfi le.xml);
myfile.xml
----------------
<?xml version="1.0" encoding="utf-8" ?>
<data>
<user id="2">
<username>tom </username>
<password>defau lt</password>
</user>
</data>
"Cobus" <co*****@hotmai l.com> wrote in message news:<uu******* *******@TK2MSFT NGP11.phx.gbl>. .. Hi
When you want to read the XML file to memory, use:
XmlDataDocument myDoc = new XmlDataDocument (); myDoc.Load( <filename>);
Then work with the DataDoc as normal to manipulate your data.
When you want to save the File back to the HDD, use normal File I/O to overwrite your existing file. Get the file's contents from the XmlDataDocument 's OuterXml property...
HTH
Cobus Lombard Application Developer Mint Net South Africa
"Gerald Maher" <ge**********@w aytohere.com> wrote in message news:d0******** *************** ***@posting.goo gle.com... Hi
Reading in XML file using C#, changing elements and saving back to the file, how can i do that ? I want to be able to read an XML file and read out Elements. for example
<name>Tom</tom>
When I read from a file i want to save the XML document in memory of the computer and when i am finished flush it back to the file, that means i want to be able to access the element in memory of the computer and when i change it will write it back with new changes.
What is the Best way to do that ? I have tried it wiht xmlReader and xmlWrite, this is not saved in the computer. bd******@hotmai l.com (Ben Dewey) wrote in message news:<a7******* *************** ***@posting.goo gle.com>... Hey,
I would just use a standard XmlDocument to do what your looking to do:
XmlDocument myDoc = new XmlDocument(); myDoc.Load(myfi le.xml); myDoc.SelectSin gleNode("//username[@id=2]/username").Valu e = "myfirstpasswor d"; myDoc.Save(myfi le.xml);
myfile.xml ---------------- <?xml version="1.0" encoding="utf-8" ?> <data> <user id="2"> <username>tom </username> <password>defau lt</password> </user> </data>
How can can I add a new node say :
<username>Peter </username>
<password></password>
in C# code
"Cobus" <co*****@hotmai l.com> wrote in message news:<uu******* *******@TK2MSFT NGP11.phx.gbl>. .. Hi
When you want to read the XML file to memory, use:
XmlDataDocument myDoc = new XmlDataDocument (); myDoc.Load( <filename>);
Then work with the DataDoc as normal to manipulate your data.
When you want to save the File back to the HDD, use normal File I/O to overwrite your existing file. Get the file's contents from the XmlDataDocument 's OuterXml property...
HTH
Cobus Lombard Application Developer Mint Net South Africa
How can i use this if 2 users on different computers using the same file ?
i.e. how can i protect 2 people writing over the same file ?
Have a look at source/version control software too.
CVS is capable and free. Bit of a pain barrier if you havent used these
tools before but they are very good at what they do, i.e. booking and
catalogue system that prevents overwrites as you suggest. http://www.cvshome.org/
Regards
Tam Inglis
"Gerald Maher" <ge**********@w aytohere.com> wrote in message
news:d0******** *************** ***@posting.goo gle.com... "Cobus" <co*****@hotmai l.com> wrote in message
news:<uu******* *******@TK2MSFT NGP11.phx.gbl>. .. Hi
When you want to read the XML file to memory, use:
XmlDataDocument myDoc = new XmlDataDocument (); myDoc.Load( <filename>);
Then work with the DataDoc as normal to manipulate your data.
When you want to save the File back to the HDD, use normal File I/O to overwrite your existing file. Get the file's contents from the XmlDataDocument 's OuterXml property...
HTH
Cobus Lombard Application Developer Mint Net South Africa
How can i use this if 2 users on different computers using the same file ?
i.e. how can i protect 2 people writing over the same file ?
"Tam Inglis" <jo***********@ btclick.com> wrote in message news:<br******* ***@sparta.btin ternet.com>... Have a look at source/version control software too.
CVS is capable and free. Bit of a pain barrier if you havent used these tools before but they are very good at what they do, i.e. booking and catalogue system that prevents overwrites as you suggest.
http://www.cvshome.org/
Regards
Tam Inglis
"Gerald Maher" <ge**********@w aytohere.com> wrote in message news:d0******** *************** ***@posting.goo gle.com... "Cobus" <co*****@hotmai l.com> wrote in message news:<uu******* *******@TK2MSFT NGP11.phx.gbl>. .. Hi
When you want to read the XML file to memory, use:
XmlDataDocument myDoc = new XmlDataDocument (); myDoc.Load( <filename>);
Then work with the DataDoc as normal to manipulate your data.
When you want to save the File back to the HDD, use normal File I/O to overwrite your existing file. Get the file's contents from the XmlDataDocument 's OuterXml property...
HTH
Cobus Lombard Application Developer Mint Net South Africa
How can i use this if 2 users on different computers using the same file ?
i.e. how can i protect 2 people writing over the same file ?
???
How does this help ? how can i access 2 files with 2 different computers This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the file...
Thank you to all of you who can help me with this one...
|
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much text is available until I
have read it... which seems to imply that multiple reads of the input
stream will be inevitable.
Now I can correctly...
|
by: Oliver Knoll |
last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode
(that is just writing, right?). How would one reopen it for reading?
I got the following (which works):
FILE *tmpFile = tmpfile();
/* write into tmpFile */
...
|
by: KevinD |
last post by:
assumption: I am new to C and old to COBOL
I have been reading a lot (self teaching) but something is not sinking
in with respect to reading a simple file - one record at a time.
Using C, I am trying to read a flatfile. In COBOL, my simple file
layout and READ statement would look like below.
Question: what is the standard, simple...
|
by: Sabin Finateanu |
last post by:
Hi I'm having problem reading a file from my program and I think it's from a
procedure I'm using but I don't see where I'm going wrong. Here is the code:
public bool AllowUsage()
{
OperatingSystem os = Environment.OSVersion;
AppDomain ad = Thread.GetDomain();
| |
by: John Dann |
last post by:
I'm trying to read some binary data from a file created by another
program. I know the binary file format but can't change or control the
format. The binary data is organised such that it should populate a
series of structures of specified variable composition.
I have the structures created OK, but actually reading the files is
giving me an...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: Use*n*x |
last post by:
Hello,
I have a binary file (image file) and am reading 4-bytes at a time. The
File size is 63,480,320 bytes. My assumption is that if I loop through
this file reading 4 bytes at a time, I should loop 15,870,080 times.
The code is:
newprogram.cpp
=============
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing and why I have to do it. Hopefully someone has a suggestion...
Alright, so I'm using a gps-simulation program that outputs gps data, like...
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features to an old program that I wrote in delphi
and it's a good opportunity to start with c++.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |