ahit
asked on
how to pass XmlDocument Object to XmlTextWriter
Hi Experts,
I have a method which takes XmlDocument object as an argument. Now This XmlDocument Object contains the File Name in which I m interested to write my XML. Now How can I use this object to write into my XML file???
I m using XmlTextWriter, but producing Error.....
For clarity I m writing the Code 4 u..
XmlDocument document = new XmlDocument();
string filename="Peter.xml";
document.Load(filename);
// or
document.Save(filename); // Not Sure
myclass.mymethod(document) ; // call 2 mthod
................
..................
public void mymethod(XmlDocument doc) // method definition
{
XmlTextWriter tw = XmlTextWriter(doc,null);
tw.WriteStartDocument();
tw.WriteStartElement(c.Get Type().ToS tring());
.......................... ..
}
It is giving me error
C:\Serializer\Class1.cs(51 ): 'System.Xml.XmlTextWriter' denotes a 'class' which is not valid in the given context....
if I try to Change XmlDocument object to String variable, It also produces an error.... Type Error
Note 1: I have to make such a method in which I have to pass an XmlDocument Object and write into the file( plz Don't say Y i want to pass XmlDocument object)
Note2: I m not sure how to use AppendChild, CreateElement .... Tell me ..preferably with any example
Plz anyone who can give me any clue how to do it ?
All I NEED to write the XmlDocument object to use for writing XML file....
Looking forward for a quick Response..
Thanks!
Ahit...
I have a method which takes XmlDocument object as an argument. Now This XmlDocument Object contains the File Name in which I m interested to write my XML. Now How can I use this object to write into my XML file???
I m using XmlTextWriter, but producing Error.....
For clarity I m writing the Code 4 u..
XmlDocument document = new XmlDocument();
string filename="Peter.xml";
document.Load(filename);
// or
document.Save(filename); // Not Sure
myclass.mymethod(document)
................
..................
public void mymethod(XmlDocument doc) // method definition
{
XmlTextWriter tw = XmlTextWriter(doc,null);
tw.WriteStartDocument();
tw.WriteStartElement(c.Get
..........................
}
It is giving me error
C:\Serializer\Class1.cs(51
if I try to Change XmlDocument object to String variable, It also produces an error.... Type Error
Note 1: I have to make such a method in which I have to pass an XmlDocument Object and write into the file( plz Don't say Y i want to pass XmlDocument object)
Note2: I m not sure how to use AppendChild, CreateElement .... Tell me ..preferably with any example
Plz anyone who can give me any clue how to do it ?
All I NEED to write the XmlDocument object to use for writing XML file....
Looking forward for a quick Response..
Thanks!
Ahit...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.