473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to write to an xml file

I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML file
a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI
Nov 16 '05 #1
6 1568
XmlTextWriter
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
"ALI-R" <ne****@microsoft.com> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML file a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI

Nov 16 '05 #2
Hi Ali,
Create an object representation of the xml file and fill it with data:

object NameValue
{
string Name;
string Value;
}

object Settings
{
string ReportName;
string ReportPath;
string ServerPath;
NameValue Pairs;
}

Settings settingsObject=new Settings();
settingsObject.ReportName="My report";
settingsObject.ReportPath="c:\\...";
settingsObject.ServerName="http://server...";

Then use XmlSerializer in the System.Xml.Serialization namespace and
serialize the object to disk:

FileStream fs=File.Create("mysettings.xml");
try
{
XmlSerializer serializer=new XmlSerializer(typeof(Settings));
serializer.Serialize(fs,settingsObject);
}
finally
{
fs.Close();
}

There you go

/Hugo

On Thu, 18 Nov 2004 16:39:15 -0800, ALI-R wrote:
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML file
a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI

Nov 16 '05 #3
I would just create a class and use xmlseralizer to serialize it to xml.\
pubic class MyClass
{
public string RptName;
public string RptPath;
pubic DictionaryEntry[] Values;

public string ToXmlString()
{
// use XmlSerializer ...
}
public static MyClass FromXmlString()
{
// use XmlSerializer. Not at my computer to give you better.
}
}

"ALI-R" <ne****@microsoft.com> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML
file
a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI

Nov 16 '05 #4
Is the second method ( FromXmlString) for Deserilizing??
"William Stacey" <st*****@mvps.org> wrote in message
news:uQ*************@TK2MSFTNGP11.phx.gbl...
I would just create a class and use xmlseralizer to serialize it to xml.\
pubic class MyClass
{
public string RptName;
public string RptPath;
pubic DictionaryEntry[] Values;

public string ToXmlString()
{
// use XmlSerializer ...
}
public static MyClass FromXmlString()
{
// use XmlSerializer. Not at my computer to give you better.
}
}

"ALI-R" <ne****@microsoft.com> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML
file
a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI


Nov 16 '05 #5
where should these object be? in a class? or in my code?

thanks for your help.
ALI
"Hugo Wetterberg" <hu*************@smi.mas.lu.se> wrote in message
news:1t*****************************@40tude.net...
Hi Ali,
Create an object representation of the xml file and fill it with data:

object NameValue
{
string Name;
string Value;
}

object Settings
{
string ReportName;
string ReportPath;
string ServerPath;
NameValue Pairs;
}

Settings settingsObject=new Settings();
settingsObject.ReportName="My report";
settingsObject.ReportPath="c:\\...";
settingsObject.ServerName="http://server...";

Then use XmlSerializer in the System.Xml.Serialization namespace and
serialize the object to disk:

FileStream fs=File.Create("mysettings.xml");
try
{
XmlSerializer serializer=new XmlSerializer(typeof(Settings));
serializer.Serialize(fs,settingsObject);
}
finally
{
fs.Close();
}

There you go

/Hugo

On Thu, 18 Nov 2004 16:39:15 -0800, ALI-R wrote:
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML file a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI

Nov 16 '05 #6
where and how should I initialize the Pairs array?
"Hugo Wetterberg" <hu*************@smi.mas.lu.se> wrote in message
news:1t*****************************@40tude.net...
Hi Ali,
Create an object representation of the xml file and fill it with data:

object NameValue
{
string Name;
string Value;
}

object Settings
{
string ReportName;
string ReportPath;
string ServerPath;
NameValue Pairs;
}

Settings settingsObject=new Settings();
settingsObject.ReportName="My report";
settingsObject.ReportPath="c:\\...";
settingsObject.ServerName="http://server...";

Then use XmlSerializer in the System.Xml.Serialization namespace and
serialize the object to disk:

FileStream fs=File.Create("mysettings.xml");
try
{
XmlSerializer serializer=new XmlSerializer(typeof(Settings));
serializer.Serialize(fs,settingsObject);
}
finally
{
fs.Close();
}

There you go

/Hugo

On Thu, 18 Nov 2004 16:39:15 -0800, ALI-R wrote:
I have tree variable with their values:

1) rptName="report1"
2) rptPath="c:\......"
3) serverPath=http://server...
and
4)an arry which contain Name/value pairs.

what is the best way of wrting them into an xml file??
these Xml files are stored in the same directory so I also give the XML file a uniqe name so I can make sure that it dosn't overrite the other file.
thanks for your help.
ALI


Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
6
by: sambuela | last post by:
How can I write message to the file located in the wwwroot directory? It seems that IIS protect these files. Let make me cannot do the I/O writing sucessfully. I try to open file's write...
2
by: ykgoh | last post by:
Hi. I've a problem of being able to create and remove a directory but unable to write a file inside the created directory for some strange reason. I suspect that this problem could be vaguely...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
1
by: =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post by:
Hello All, Our application write logs to a file in a folder. Before our application starts writing to that file, I want to check if the current user has write access to that file, for example,...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
6
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...

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.