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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:59:56+00:00 2026-05-22T15:59:56+00:00

I need to generate the following XML: <Learner xmlns=some.domain.api> <ActivationDate>1999-05-31T11:20:00</ActivationDate> <EmailAddress>String content</EmailAddress> <ExpirationDate>1999-05-31T11:20:00</ExpirationDate> <FederalId>String

  • 0

I need to generate the following XML:

<Learner xmlns="some.domain.api">
  <ActivationDate>1999-05-31T11:20:00</ActivationDate>
  <EmailAddress>String content</EmailAddress>
  <ExpirationDate>1999-05-31T11:20:00</ExpirationDate>
  <FederalId>String content</FederalId>
  <FirstName>String content</FirstName>
  <Grade>K</Grade>
  <LastName>String content</LastName>
  <MiddleName>String content</MiddleName>
  <UserName>String content</UserName>
  <Password>String content</Password>
  <SISId>String content</SISId>
  <StateId>String content</StateId>
  <Status>Active</Status>
</Learner>

I have read these questions:

  • How can I make the xmlserializer only serialize plain xml?
  • Automatically generate XSD to C# in Visual Studio IDE

I am using Xsd2Code to generate the classes from XSD. That is working.

I have tried this:

private static string SerializeXML(Object obj)
{
    XmlSerializer serializer = new XmlSerializer(obj.GetType(), "some.domain.api");

    //settings
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;
    settings.OmitXmlDeclaration = true;

    StringWriter stream = new StringWriter();
    XmlWriter writer = XmlWriter.Create(stream, settings);

    serializer.Serialize(writer, obj);
    return stream.ToString();
}

But it produces this:

<Learner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="some.domain.api">
  <ActivationDate>1999-05-31T11:20:00</ActivationDate>
  <EmailAddress>String content</EmailAddress>
  <ExpirationDate>1999-05-31T11:20:00</ExpirationDate>
  <FederalId>String content</FederalId>
  <FirstName>String content</FirstName>
  <Grade>K</Grade>
  <LastName>String content</LastName>
  <MiddleName>String content</MiddleName>
  <UserName>String content</UserName>
  <Password>String content</Password>
  <SISId>String content</SISId>
  <StateId>String content</StateId>
  <Status>Active</Status>
</Learner>

I want to get rid of xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema".

How to?

Update

I have also already tried this using XmlSerializerNamespaces. If I add namespaces like this, using my implementation above with the necessary adjustments:

XmlSerializerNamespaces namespaces = 
    new XmlSerializerNamespaces(new[] { new XmlQualifiedName("ns","some.domain.api") });

I get this:

<Learner xmlns:ns="some.domain.api">

But I need this:

<Learner xmlns="some.domain.api">

If I add namespaces like this, using my implementation above with the necessary adjustments:

XmlSerializerNamespaces namespaces = 
    new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });

I get this:

<q1:Learner xmlns:ns="some.domain.api">

for all XML tags!

Is there any way I can do to get my desired output? I really don’t want to use StringBuilder for this task…

  • 1 1 Answer
  • 1 View
  • 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-22T15:59:57+00:00Added an answer on May 22, 2026 at 3:59 pm

    You can do as you did up there with:

    XmlSerializerNamespaces namespaces = 
    new XmlSerializerNamespaces(new[] { new XmlQualifiedName("ns","some.domain.api") });
    

    and after writing the file do this:

    StreamReader reader = new StreamReader(file_name);
    string content = reader.ReadToEnd();
    reader.Close();
    content = Regex.Replace(content, ":ns", "");
    StreamWriter writer = new StreamWriter(file_name);
    writer.Write(content);
    writer.Close();
    

    Not the most elegant, but it works.

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

Sidebar

Related Questions

I need to generate XML in the following form: <ns1:root xmlns:ns1=http://example.com/xmlns1 xmlns:ns2=http://example.com/xmlns2> <ns2:item ns2:param=value
I need so generate XML like the following: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <urlset xmlns=http://www.sitemaps.org/schemas/sitemap/0.9
I have the following requirement: Based on some user input, I need to generate
I need to generate the following XML with SOAP: ... <InternationalShippingServiceOption> <ShippingService>StandardInternational</ShippingService> <ShippingServiceCost currencyID=USD>39.99</ShippingServiceCost>
I need to generate a node in a XML file with the following structure:
I have the following xml I need to read the values of: <po-response xmlns=http://test.com<
I need to generate the following in ASP.NET page. What's the best, easiest way
I would like to achieve the following, I need to generate report for multiple
I need to dynamically generate radio or checkbox by jQuery. I use the following
I have the following problem: I need to use XSLFO to generate a 2-column

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.