469,890 Members | 1,414 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

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 1475
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ellixis | last post: by
1 post views Thread by =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post: by
6 posts views Thread by globalrev | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.