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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:23:36+00:00 2026-05-14T03:23:36+00:00

I have the following variable that accepts a file name: var xtr = new

  • 0

I have the following variable that accepts a file name:

var xtr = new XmlTextReader(xmlFileName) { WhitespaceHandling = WhitespaceHandling.None };
var xd = new XmlDocument();
xd.Load(xtr);

I would like to change it so that I can pass in an object. I don’t want to have to serialize the object to file first.

Is this possible?

Update:

My original intentions were to take an xml document, merge some xslt (stored in a file), then output and return html… like this:

public string TransformXml(string xmlFileName, string xslFileName)
{
     var xtr = new XmlTextReader(xmlFileName) { WhitespaceHandling = WhitespaceHandling.None };
     var xd = new XmlDocument();
     xd.Load(xtr);

     var xslt = new System.Xml.Xsl.XslCompiledTransform();
     xslt.Load(xslFileName);
     var stm = new MemoryStream();
     xslt.Transform(xd, null, stm);
     stm.Position = 1;
     var sr = new StreamReader(stm);
     xtr.Close();
     return sr.ReadToEnd();
}

In the above code I am reading in the xml from a file. Now what I would like to do is just work with the object, before it was serialized to the file.

So let me illustrate my problem using code

public string TransformXMLFromObject(myObjType myobj , string xsltFileName)
{
     // Notice the xslt stays the same.
     // Its in these next few lines that I can't figure out how to load the xml document (xd) from an object, and not from a file....

     var xtr = new XmlTextReader(xmlFileName) { WhitespaceHandling = WhitespaceHandling.None };
     var xd = new XmlDocument();
     xd.Load(xtr);
}
  • 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-14T03:23:37+00:00Added an answer on May 14, 2026 at 3:23 am

    You want to turn an arbitrary .NET object into a serialized XML string? Nothing simpler than that!! 🙂

    public string SerializeToXml(object input)
    {
       XmlSerializer ser = new XmlSerializer(input.GetType(), "http://schemas.yournamespace.com");
       string result = string.Empty;
    
       using(MemoryStream memStm = new MemoryStream())
       {
         ser.Serialize(memStm, input);
    
         memStm.Position = 0;
         result = new StreamReader(memStm).ReadToEnd();
       } 
    
       return result;
    } 
    

    That should to it 🙂 Of course you might want to make the default XML namespace configurable as a parameter, too.

    Or do you want to be able to create an XmlDocument on top of an existing object?

    public XmlDocument SerializeToXmlDocument(object input)
    {
       XmlSerializer ser = new XmlSerializer(input.GetType(), "http://schemas.yournamespace.com");
    
       XmlDocument xd = null;
    
       using(MemoryStream memStm = new MemoryStream())
       {
         ser.Serialize(memStm, input);
    
         memStm.Position = 0;
    
         XmlReaderSettings settings = new XmlReaderSettings();
         settings.IgnoreWhitespace = true;
    
         using(var xtr = XmlReader.Create(memStm, settings))
         {  
            xd = new XmlDocument();
            xd.Load(xtr);
         }
       }
    
       return xd;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that contains the following JSON string: { 0 : Jun
I have the following function. The problem is that the $lang variable will vary
I have the following string as a variable: var name1 = '001-C6AL7_deepgreen_C3AE7_tankhakinavy_FJAG7_blackredmulti_FBAE7_tanbrown.jpg'; Which is
I have the following code. Given that the variable u1 can be any of
I have a variable that will have the following values: blah = # 1,
i have a function that accepts variable number of parameters (meaning I can put
I have a function that accepts a variable length array of 80 character strings.
I am new to Ruby, I'm writing a script that does the following: Accepts
So I have a class that has the following member variables. I have get
I have the following variable: pageID = 7 I'd like to increment this number

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.