469,613 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

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 2166
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

Post your reply

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

Similar topics

2 posts views Thread by Jesper Stocholm | last post: by
3 posts views Thread by Gustaf Liljegren | last post: by
8 posts views Thread by Charles.Deisler | last post: by
reply views Thread by Martin | last post: by
reply views Thread by Martin | last post: by
4 posts views Thread by quest | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.