Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to pass XmlDocument Object to XmlTextWriter

Posted on 2006-11-23
4
Medium Priority
?
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
rameedev earned 2000 total points
ID: 18006437
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

722 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