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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:09:37+00:00 2026-05-31T13:09:37+00:00

I get multiple XSDs from various clients and I need to give them the

  • 0

I get multiple XSDs from various clients and I need to give them the data in XML format conforming to the XSD that they have provided. I already have written a code to dynamically create and compile a class from XSD using codedom, System.Reflection and codeprovider.
Now my plan is to get data from database through multiple queries and map the fields to the properties of the dynamic class created and serialize it. I am looking for a generic way of mapping these fields, which can be used for any type of xsd and by just mapping the fields it will serialize and gives XML file. As for the queries I am putting them in the config file. Is a generic solution do-able? Any ideas or pointers on how to go about it?

  • 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-31T13:09:38+00:00Added an answer on May 31, 2026 at 1:09 pm

    I was able to resolve this. Here are the steps I used: I first created an in-memory run time assembly from xsd using reflection and codedom.compiler with serializable attributes. Using the reflection I created instance of the classes in that assembly and assigned properties from the data I got from database. This class I forwarded to another method that serializes takes an object and serializes it to xml.

    As far as the mapping, I made sure that the database column names needs to be matched with the xml attribute names and with that I was able map and invoke them.

    Here is the snippet:

    object fxClass = myAssembly.CreateInstance(cls.FullName);
    Type t = fxClass.GetType();
    
    
    var arrRates = Array.CreateInstance(t, tab.Rows.Count);
    int i =0;
    foreach (DataRow dr in tab.Rows)
    {
        fxClass = myAssembly.CreateInstance(cls.FullName);
        PropertyInfo[] fxRateProperties = t.GetProperties();
        foreach (PropertyInfo prop in fxRateProperties)
        {
            string rowVal = dr[prop.Name].ToString();
    
            if (prop.PropertyType == typeof(DateTime))
            {
                prop.SetValue(fxClass, util.convertToDate(rowVal), null);
            }
            else if (prop.PropertyType == typeof(bool))
            {
                prop.SetValue(fxClass, util.convertToBoolean(rowVal), null);
            }
            else if (prop.PropertyType == typeof(decimal))
            {
                prop.SetValue(fxClass, util.convertToDecimal(rowVal), null);
            }
            else prop.SetValue(fxClass, rowVal, null);                                           
        }
        arrRates.SetValue(fxClass,i);
        i++;
    }
    myClass.GetType().GetProperty("ForexRates").SetValue(myClass, arrRates, null);
    

    Then pass myClass object to serialize method that accepts object type and that’s it

    public void serializeXML(object portfolio, string xmlPath)
    {
        XmlSerializer serial = new XmlSerializer(portfolio.GetType());
        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
        ns.Add("", "");
        try
        {
            using (FileStream fs = new FileStream(xmlPath, FileMode.Create, FileAccess.Write))
            {
                using (XmlTextWriter tw = new XmlTextWriter(fs, Encoding.UTF8))
                {
                    tw.Formatting = Formatting.Indented;
                    serial.Serialize(tw, portfolio, ns);
                }
            }
         }
    }
    

    For this, now I am planning to add a UI piece where the mappings like “ForexRates” are saved in the database and it would then open to any of the xsd types.

    Thanks very much for you responses.

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

Sidebar

Related Questions

I need to get multiple variables up into my JS code from my C#
I have a program that need to get multiple cstrings. I current get one
I'm using the Oracle data libraries in .NET to get multiple tables returned from
I need to get multiple posts in wordpress by ID. get_posts('p=34,36'); I assumed that
Is there a better way to get multiple top X results from a MySQL
Do we get multiple copies of the pointers yet the data members are still
Is there a way to get multiple counts depending on multiple conditions from the
Following on from an earlier question I'm trying to get multiple (widgets or in
I'm trying to parse a single string and get multiple chunks of data out
I'm trying to get multiple clients to connect to a server. What I've managed

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.