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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:34:34+00:00 2026-05-20T04:34:34+00:00

I have classes as follows namespace Coverage { public class ClassInfo { public string

  • 0

I have classes as follows

namespace Coverage {
    public class ClassInfo {
        public string ClassName;
        public int BlocksCovered;
        public int BlocksNotCovered;

        public ClassInfo() {}

        public ClassInfo(string ClassName, int BlocksCovered, int BlocksNotCovered) 
        {
            this.ClassName = ClassName;
            this.BlocksCovered = BlocksCovered;
            this.BlocksNotCovered = BlocksNotCovered;
        }
    }

    public class Module {
        public List<ClassInfo> ClassInfoList;
        public int BlocksCovered;
        public int BlocksNotCovered;
        public string moduleName;

        public Module()
        {
            ClassInfoList = new List<ClassInfo>();
            BlocksCovered = 0;
            BlocksNotCovered = 0;
            moduleName = "";
        }

With the following serializer code

XmlSerializer SerializerObj = new XmlSerializer(typeof(Module));
// Create a new file stream to write the serialized object to a file
TextWriter WriteFileStream = new StreamWriter(@"test.xml");
SerializerObj.Serialize(WriteFileStream, report);
WriteFileStream.Close();

I can get the following XML file.

<?xml version="1.0" encoding="utf-8"?>
<Module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ClassInfoList>
    <ClassInfo>
      <ClassName>Fpga::TestMe</ClassName>
      <BlocksCovered>4</BlocksCovered>
      <BlocksNotCovered>8</BlocksNotCovered>
    </ClassInfo>
    <ClassInfo>
      <ClassName>Fpga::TestMe2</ClassName>
      <BlocksCovered>4</BlocksCovered>
      <BlocksNotCovered>8</BlocksNotCovered>
    </ClassInfo>
  </ClassInfoList>
  <BlocksCovered>8</BlocksCovered>
  <BlocksNotCovered>16</BlocksNotCovered>
  <moduleName>helloclass.exe</moduleName>
</Module>
  • Q1 : How can I remove the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://... to have simple element <Module>..</Module>?
  • Q2 : The XML element name is exactly the same as the class name or variable name. Can I replace it with my own?
  • Q3 : Can I remove the outer <ClassInfoList>?

For example, how can I generate the XML as follows:

<?xml version="1.0" encoding="utf-8"?>
<Module>
  <Class>
      <ClassName>Fpga::TestMe</ClassName>
      <BlocksCovered>4</BlocksCovered>
      <BlocksNotCovered>8</BlocksNotCovered>
  </Class>
  <Class>
      <ClassName>Fpga::TestMe2</ClassName>
      <BlocksCovered>4</BlocksCovered>
      <BlocksNotCovered>8</BlocksNotCovered>
  </Class>
  <BlocksCovered>8</BlocksCovered>
  <BlocksNotCovered>16</BlocksNotCovered>
  <moduleName>helloclass.exe</moduleName>
</Module>
  • 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-20T04:34:35+00:00Added an answer on May 20, 2026 at 4:34 am

    (btw, it doesn’t tie to the question, but you should aim to avoid public fields, for lots of reasons covered in many stackoverflow questions)

    Q3: Simply:

    [XmlElement("Class")]
    public List<ClassInfo> ClassInfoList;
    

    Q2 re the top level name; you can use

    [XmlRoot("somethingFun")]
    public class Module { ... }
    

    Q2 re member names:

    [XmlElement("blocks")]
    public int BlocksCovered;
    

    (see also [XmlAttribute(...)])

    Q1 Removing the xsi etc can be done with XmlSerializerNamespaces:

    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
    ns.Add("", "");
    var ser = new XmlSerializer(typeof(Module));
    ser.Serialize(destination, module, ns);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes layed out like this class A { public virtual void
I have two Java classes: B, which extends another class A, as follows :
I have seen some C++ classes with a destructor defined as follows: class someClass
I have two classes, Foo and Bar, that have constructors like this: class Foo
So I have this class public static class MyClass { static MyClass() { ...
I have two classes public class A { public A() { } } public
I have two classes, and want to include a static instance of one class
I have multiple classes that all derive from a base class, now some of
In my asp.net web app. I have three classes (inside app_code folder) under namespace
I have a need for methods in several classes that must always follow a

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.