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 90015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:48:26+00:00 2026-05-10T22:48:26+00:00

I want to read an xml file, apply a transform, then write to another

  • 0

I want to read an xml file, apply a transform, then write to another file. The best way I can think of is this:

using (XmlTextReader reader = new XmlTextReader(new FileStream(_source, FileMode.Open))) using (XmlTextWriter writer = new XmlTextWriter(new StreamWriter(_destination))) {    _xslTransform.Transform(reader, writer); } 

But I really want to get a progress. If I’m just copying data I can do something like this (this might not be 100% right but something like this):

using (BinaryReader reader = new BinaryReader(new FileStream(_source, FileMode.Open))) using (BinaryWriter writer = new StreamWriter(_destination)) {     byte[] buffer = new byte[2048];     int read = 0;     int actual = 0;     long total = reader.BaseStream.Length;      while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)     {         writer.Write(buffer, 0, read);         actual = (actual <= total ? actual + read : read);         updateProgress(Convert.ToInt32(actual / total * 100));     } } 

So is there some way of doing this when using the XslCompiledTransform. I could just read it into memory first before writing to the file but I want to limit the amount of memory used, or does the XslCompiledTransform load it all into memory anyway?

I hope this makes some sort of sense, thanks!

Adam.

  • 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-10T22:48:26+00:00Added an answer on May 10, 2026 at 10:48 pm

    An option is to send xsl:message messages from within the transform and listen to these messages.

    With this approach you have to run over the input document first and count the nodes that your transform ‘iterates’ over. This can be done using a very basic XSLT which just sends a message on every node of interest.

    Then – during the actual transform – each time you hit a node of interest you can send an

    <xsl:message terminate='no'>progress:mynode</xsl:message> 

    progress message.

    This message can be intercepted in the calling C# code with a message listener. You could put the following code into a small class for applying an XSL transform. It’s just a basic sample for illustrating; I hope you get the idea:

    protected event MessageListener progressMessageIntercepted;  public void AddProgressMessageListener(MessageListener listener) {     progressMessageIntercepted += listener; }  public void RemoveMessageListeners() {     progressMessageIntercepted = null; }  protected void MessageCallBack(object sender, XsltMessageEncounteredEventArgs e) {     if (e.Message.StartsWith('progress:'))     {         if (progressMessageIntercepted != null)         {             progressMessageIntercepted(this, null);         }     } }  protected void Transform(string inputFile, string outputFile, string xsltFile) {     XslCompiledTransform xslt = new XslCompiledTransform();     xslt.Load(xsltFile);     XsltArgumentList parameters = new XsltArgumentList();     parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);      using (XmlWriter xmlWriter = XmlWriter.Create(outputFile))     {         xslt.Transform(inputFile, parameters, xmlWriter);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read this xml file using Id on <page> tag. <?xml version=1.0
I want to read a xml file using Linq. This xml file is composed
I want to read an XML file located here The data looks like this
I want to read a XML file, using XMLReader but the END ELEMENT is
I want to read xml file in asp.net use c# and also to write
i am using xml parser to read data from xml file. In this file
I want to open and read an XML file using php, but I wont
Is there a way I can read the contents of plist file and put
I want to read XML data using XPath in Java, so for the information
I want to read xml file which looks like the following ... I have

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.