[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I write the xml to a string?

Posted on 2007-10-17
6
Medium Priority
?
302 Views
Last Modified: 2013-11-26
I need to create a XML file on the fly. The current code only writes the xml to the file as follows:

XmlTextWriter writer = new XmlTextWriter(xmlMyRequestFile, Encoding.UTF8);

How do I write the xml to a string?
0
Comment
Question by:chuang4630
  • 3
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20094988
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
0
 
LVL 1

Author Comment

by:chuang4630
ID: 20095037
The compiler gives me the error:

Error      4      The best overloaded method match for 'System.Xml.XmlTextWriter.XmlTextWriter(System.IO.Stream, System.Text.Encoding)' has some invalid arguments      C:\Documents and Settings\Chris Huang\My Documents\Visual Studio 2005\Projects\Hilton.CCS.Business\OrderShipFromATT.cs      135      36      Hilton.CCS.Business
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20095333
Try with something like:

                    StringBuilder sb = new StringBuilder();
                    XmlWriter xw = XmlTextWriter.Create(sb, ws);
                   
                    // some xml writting
                    // xw.WriteStartElement(...);
                    // xw.WriteEndElement();

                    xw.Close();
                    string s = sb.ToString();
0
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.

 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 total points
ID: 20095360
You will need previously:
                    XmlWriterSettings ws = new XmlWriterSettings();
So you can change some serialization settings

0
 
LVL 1

Author Comment

by:chuang4630
ID: 20095365
What is ws in XmlTextWriter.Create(sb, ws);?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20095459
as mentioned in my previous post:  the writer settings
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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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