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

  • Home
  • SEARCH
  • 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 6616631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:36:22+00:00 2026-05-25T20:36:22+00:00

I have some XML in a XMLDocument and I want to put it into

  • 0

I have some XML in a XMLDocument and I want to put it into a StringWriter, but it always becomes empty(?) instead. I’ve tried inspecting the variables with debug, but I’m still clueless as to what’s going on.

Here’s what I have:

        XmlDocument xmlInput = new XmlDocument();
        /* after this executes, xmlInput has lots of data in it */  
        xmlInput.LoadXml(...); 

        XslCompiledTransform transform = new XslCompiledTransform();
        /* I'm pretty sure Template.xslt is being found and loaded correctly */
        transform.Load(Server.MapPath("/Files/Template.xslt")); 

        using (System.IO.StringWriter sb = new System.IO.StringWriter())
        {
            XmlWriterSettings xSettings = new XmlWriterSettings();
            xSettings.ConformanceLevel = ConformanceLevel.Fragment;
            xSettings.Encoding = Encoding.UTF8;
            /* PROBLEM: After this line, StringWriter sb is {} */
            using (XmlWriter xWriter = XmlWriter.Create(sb, xSettings))
            {
                transform.Transform(xmlInput, xWriter);
            }

            /* xmlText is empty string "" after this line */
            String xmlText = sb.ToString();

            /* ... does more stuff ... */
        }

Can I have some help? I’m really not sure where to go from here to get this working.

EDIT: Even more investigation:

        using (var stringWriter = new StringWriter())
        {
            using (var xmlTextWriter = XmlWriter.Create(stringWriter))
            {
                /* Prints lots of data to the screen */
                Response.Write(xmlInput.InnerXml);

                xmlInput.WriteTo(xmlTextWriter);
                /* Doesn't print anything to the screen */
                Response.Write(stringWriter.GetStringBuilder().ToString() );
            }
        }

BUT, flushing does the trick

                xmlInput.WriteTo(xmlTextWriter);
                xmlTextWriter.Flush();
                /* prints lots of data */
                Response.Write( stringWriter.GetStringBuilder().ToString() );
  • 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. Editorial Team
    Editorial Team
    2026-05-25T20:36:23+00:00Added an answer on May 25, 2026 at 8:36 pm

    It turns out that the XSLT file I was trying to apply required the XML to be wrapped in a certain element.

    But the flush() trick helped a lot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML in an XmlDocument, and I want to display it on
I have some xml with default namespace <a xmlns='urn:test.Schema'><b/><b/></a> and want to count the
I have some XML document with <item> elements, and i'd want to wrap each
I have an XML document that I want to generate unique IDs for. Some
I have some XML that looks like this: <abc x={></abc> I want to force
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
i have some xml with math ml inside, and i would like to find
I have some XML which contains records and sub records, like this: <data> <record
I have some XML which I'm trying to search: <debts> <section id=24 description=YYYYY> <section
I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>

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.