Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 36839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:27:23+00:00 2026-05-10T14:27:23+00:00

Here’s a quick question I’ve been banging my head against today. I’m trying to

  • 0

Here’s a quick question I’ve been banging my head against today.

I’m trying to convert a .Net dataset into an XML stream, transform it with an xsl file in memory, then output the result to a new XML file.

Here’s the current solution:

        string transformXML = @'pathToXslDocument';          XmlDocument originalXml = new XmlDocument();          XmlDocument transformedXml = new XmlDocument();          XslCompiledTransform transformer = new XslCompiledTransform();          DataSet ds = new DataSet();          string filepath;          originalXml.LoadXml(ds.GetXml()); //data loaded prior          StringBuilder sb = new StringBuilder();          XmlWriter writer = XmlWriter.Create(sb);          transformer.Load(transformXML);          transformer.Transform(originalXml, writer); //no need to select the node          transformedXml.LoadXml(sb.ToString());          transformedXml.Save(filepath);          writer.Close(); 

Here’s the original code:

BufferedStream stream = new BufferedStream(new MemoryStream());  DataSet ds = new DataSet();  da.Fill(ds);  ds.WriteXml(stream);  StreamReader sr = new StreamReader(stream, true);  stream.Position = 0; //I'm not certain if this is necessary, but for the StreamReader to read the text the position must be reset.  XmlReader reader = XmlReader.Create(sr, null);  //Problem is created here, the XmlReader is created with none of the data from the StreamReader  XslCompiledTransform transformer = new XslCompiledTransform();  transformer.Load(@'<path to xsl file>');  transformer.Transform(reader, null, writer); //Exception is thrown here, though the problem originates from the XmlReader.Create(sr, null) 

For some reason in the transformer.Transform method, the reader has no root node, in fact the reader isn’t reading anything from the StreamReader.

My questions is what is wrong with this code? Secondarily, is there a better way to convert/transform/store a dataset into XML?

Edit: Both answers were helpful and technically aku’s was closer. However I am leaning towards a solution that more closely resembles Longhorn’s after trying both solutions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:27:23+00:00Added an answer on May 10, 2026 at 2:27 pm

    I’m not sure but it seems that you didn’t reset position in stream before passing it to XmlReader. Try to seek at the beginning of your stream before trying to read from it. Also it may be necessary to close\flush stream after you wrote some data to it.

    EDIT:

    Just tried following code and it worked perfectly:

        BufferedStream stream = new BufferedStream(new MemoryStream());     stream.Write(Encoding.ASCII.GetBytes('<xml>foo</xml>'), 0, '<xml>foo</xml>'.Length);     stream.Seek(0, SeekOrigin.Begin);     StreamReader sr = new StreamReader(stream);     XmlReader reader = XmlReader.Create(sr);     while (reader.Read())     {          Console.WriteLine(reader.Value);     }     stream.Close(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 236k
  • Answers 236k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer rf1 is just the name of the variable, so even… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer Solved, there was a bug (or the feature?) in mage\sales\order\api\v2.php… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer Do you actually mean JavaDoc, in Java? If so, I… May 13, 2026 at 6:25 am

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.