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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:45:06+00:00 2026-06-05T23:45:06+00:00

I have a simple class Student under namespace School. namespace XmlTestApp { public class

  • 0

I have a simple class Student under namespace School.

namespace XmlTestApp
{
    public class Student
    {
        private string studentId;

        public string FirstName;
        public string MI;
        public string LastName;

        public Student()
        {
            //Just provided for making Serialization work as obj.GetType() needs parameterless constructor.
        }

        public Student(String studentId)
        {
            this.studentId = studentId;
        }

    }
}

Now when i serialize this, i get this as serialized xml:

<?xml version="1.0" encoding="utf-8"?>
<Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FirstName>Cad</FirstName>
  <MI>Dsart</MI>
  <LastName>dss</LastName>
</Student>

But what i want is this, basically i need the namespace prefixed to class name in xml, is this possible?

<?xml version="1.0" encoding="utf-8"?>
<XmlTestApp:Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FirstName>Cad</FirstName>
  <MI>Dsart</MI>
  <LastName>dss</LastName>
</Student>

Here’s my serialization code:

Student s = new Student("2");
            s.FirstName = "Cad";
            s.LastName = "dss";
            s.MI = "Dsart";

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(s.GetType());

            TextWriter txtW=new StreamWriter(Server.MapPath("~/XMLFile1.xml"));
            x.Serialize(txtW,s);
  • 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-06-05T23:45:08+00:00Added an answer on June 5, 2026 at 11:45 pm

    EDIT: Short answer is still yes. The proper attribute is actually the XmlType attribute. In addition, you will need to specify a namespace, and then in the serialization code you will need to specify aliases for the namespaces that will be used to qualitfy elements.

    namespace XmlTestApp
    {
        [XmlRoot(Namespace="xmltestapp", TypeName="Student")]
        public class Student
        {
            private string studentId;
    
            public string FirstName;
            public string MI;
            public string LastName;
    
            public Student()
            {
                //Just provided for making Serialization work as obj.GetType() needs parameterless constructor.
            }
    
            public Student(String studentId)
            {
                this.studentId = studentId;
            }
    
        }
    }
    
    ...
    
            Student s = new Student("2");
            s.FirstName = "Cad";
            s.LastName = "dss";
            s.MI = "Dsart";
    
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(s.GetType());
    
            System.Xml.Serialization.XmlSerializationNamespaces ns = new System.Xml.Serialization.XmlSerializationNamespaces();
    
            ns.Add("XmlTestApp", "xmltestapp");
    
            TextWriter txtW=new StreamWriter(Server.MapPath("~/XMLFile1.xml"));
            x.Serialize(txtW,s, ns); //add the namespace provider to the Serialize method
    

    You may have to play around with the setting up of the namespace to ensure it still uses the XSD/XSI from W3.org, but this should get you on the right track.

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

Sidebar

Related Questions

I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
I have a simple class inheriting from WebControl as follow: public class Instrument :
I have an simple class that I get from a webservice. public class person
I have a similar model Class Student(models.Model): A simple class which holds the basic
Say I'm modeling a school, so I have 2 Entities: Student and Class. For
I have a simple POCO class that contains the student's scores. For example: Math
I have a simple Backbone.js model: class Avia.Student extends Backbone.Model Told you it was
i have these models: public class Student { public int Id { get; set;
Let's assume we have this very simple table: |class |student| --------------- Math Alice Math
I have simple class with width and height member fields which define number of

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.