473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XmlTextWriter to XmlDocument

11
My current code contains a hardcoded filename for the XmlTextWriter to write to, and then an XmlDocument loads that file. I am looking to replace the hardcoded filename with something, anything that will retain the contents that the XmlTextWriter outputs.

My code:
Expand|Select|Wrap|Line Numbers
  1. XslCompiledTransform myXslTrans = new XslCompiledTransform();
  2. myXslTrans.Load("sortByExtension.xsl");
  3.  
  4. XmlTextWriter XmlWrite = new XmlTextWriter("results.xml", null);
  5. myXslTrans.Transform(tvXML, null, XmlWrite);
  6. XmlWrite.Close();
  7.  
  8. XmlDocument sortedXML = new XmlDocument();
  9. sortedXML.Load("results.xml");
  10. return sortedXML;
  11.  
What can I replace "results.xml" with? A Stream? BufferedStream? XmlWriter? I'm not sure what to do with it.

Andrew
Jul 19 '07 #1
2 2348
jkmyoung
2,057 Expert 2GB
I suggest making XmlWrite a Stream, and use the corresponding functions
transform
http://msdn2.microsoft.com/en-us/library/ms163440.aspx

load
http://msdn2.microsoft.com/en-us/library/e48zttz7.aspx
Jul 19 '07 #2
ajc308
11
For anyone that may have this problem in the future, this is how I solved it:

Expand|Select|Wrap|Line Numbers
  1.  
  2. XslCompiledTransform myXslTrans = new XslCompiledTransform();
  3. myXslTrans.Load("sortByExtension.xsl");
  4. StringBuilder XmlStringBuilder = new StringBuilder();
  5. XmlWriter myXmlWriter = XmlWriter.Create(XmlStringBuilder);
  6. myXslTrans.Transform(TreeViewXML, null, myXmlWriter);
  7. XmlDocument sortedXML = new XmlDocument();
  8. sortedXML.LoadXml(XmlStringBuilder.ToString());
  9.  
  10.  
Jul 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
2
by: Jesper Stocholm | last post by:
I use an XmlTextWriter to generate xml data. The declaration is: System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb);...
4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
3
by: Gustaf Liljegren | last post by:
I think I must use MemoryStream, but whenever I search for examples of MemoryStream, I get lots byte-per-byte reading, buffers and so on. It's hard to understand and seem overkill for my case...
8
by: Charles.Deisler | last post by:
Im currently using the following code.. XmlDocument xmlData = new XmlDocument(); XmlTextWriter xmlwriter = new XmlTextWriter(Response.OutputStream,System.Text.Encoding.UTF8); XmlReader...
1
by: st | last post by:
Hi, I've a routine that exports a DB query to Excel by building an XmlDocument and saving to a XmlTextWriter. I'm having trouble with carriage returns in a mailing address not showing up in the...
0
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned...
0
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned...
4
by: quest | last post by:
Is there anyway I can generate the xml in the following format using XmlTextWriter ? Intended output: <?xml version="1.0" ?> I tried: XmlTextWriter xmlWriter = new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.