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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:50:27+00:00 2026-05-24T20:50:27+00:00

I am using an XmlSerializer to serialize an object to xml. After the object

  • 0

I am using an XmlSerializer to serialize an object to xml. After the object gets serialized, I end up with something like…

<?xml version="1.0" encoding="utf-8"?>
<xml xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</xml>

I need to have it return simply…

<xml></xml>

Is there a way to serialize xml without the extra information? I realize strictly proper xml requires these additional elements, but I need the simpler form as I am appending these xml strings together to form a larger xml blob.

UPDATE

I was able to get the following code to work…

    public static string Serialize(object o)
    {
        XmlWriterSettings xws = new XmlWriterSettings();
        xws.OmitXmlDeclaration = true;
        xws.Indent = true;

        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
        ns.Add(String.Empty, String.Empty);

        StringBuilder sb = new StringBuilder();
        XmlWriter xmlw = XmlWriter.Create(sb, xws);
        XmlSerializer serializer = new XmlSerializer(o.GetType());
        serializer.Serialize(xmlw, o, ns);
        xmlw.Flush();

        return sb.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-24T20:50:28+00:00Added an answer on May 24, 2026 at 8:50 pm

    In C#, you can do something like this:

    XmlSerializer serializer = new XmlSerializer(typeof(object));
    StringWriter stringWriter = new StringWriter();
    
    using (XmlWriter writer = XmlWriter.Create(stringWriter, new XmlWriterSettings() { OmitXmlDeclaration = true }))
    {
        serializer.Serialize(writer, this, new XmlSerializerNamespaces() { "",""});
    }
    string xmlText = stringWriter.ToString();
    

    Explanation:

    OmitXmlDeclaration = true makes it remove the declaration.

    new XmlSerializerNamespaces() { "",""} removes the namespaces.

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

Sidebar

Related Questions

Currently I'm using XmlSerializer to serialize and deserialize an object. The xml is generated
I serialize an XML file into an object using the built-in .NET functionality (XmlSerializer.Deserialize).
In C# / .NET 2.0, when I serialize an object using XmlSerializer , what's
Normally, when using the XMLSerializer to automagically serialize an ISerializable object, a .dll file
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I am using XmlSerializer to write and read an object to xml in C#.
I am calling a REST webservice. The response looks something like this: <?xml version=\1.0\
I were using FileStream to Serialize an Object to Xml and Save to the
What is a better approach to serialize custom class: using XMLSerializer or BinarryFormatter and
I am using the XML serializer. I would like it to convert all my

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.