Solved

how to pass XmlDocument Object to XmlTextWriter

Posted on 2006-11-23
4
404 Views
Last Modified: 2008-02-01
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.GetType().ToString());
 ............................
}

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...
 
0
Comment
Question by:ahit
4 Comments
 
LVL 5

Accepted Solution

by:
rameedev earned 500 total points
Comment Utility
First of all The line of Code  "XmlTextWriter tw = XmlTextWriter(doc,null);" is wrong...there is no overloaded contructor for XmlTextWriter which takes an xmldocument as an arguement...

If you are interested to retreive the filename inside your xmldocument then you need to retreive it from the Xmldocument. You could do this by calling say SelectSingleNode or SelectNode methods which takes an xpath parameter to the node...

Ex:- if we assume your FileName xmlnode is under Root/Parent then
string sPath = "Root/Parent/FileName";
XmlNode nFileName = nd.SelectSingleNode(sPath);
string sFileName = nFileName .InnerText

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Image(7) 1 33
String manipulation 15 49
Get String split 5 31
Is setting this variable making a duplicate in memory 4 8
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now