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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:41:18+00:00 2026-05-17T17:41:18+00:00

I’ve been looking around for this for quite some time and cannot seem to

  • 0

I’ve been looking around for this for quite some time and cannot seem to get anywhere. I need to find a way to accomplisht the following two tasks, based on a .Net Entity object:

  1. Create an XML file that contains the data in this entities, complete, with cascading nodes (representing foreign key relationships, basically). I’ve considered copying the data to a DataSet and then doing a WriteXml() on it, but this seems like an overkill. Entities must have a more direct way. Note, though, that I’m not trying to serialize the object. I just need the data in a simple XML file.
  2. Related to point 1, I need to also save an XSD representing the schema of this Entity, to go hand in hand with the XML mentioned above. Again, going through a DataSet and then WriteXmlSchema() is an option, but feels like overkill.

Is there anything in the Entity universe that can help do this in a simple way ?

Thx.

  • 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-17T17:41:18+00:00Added an answer on May 17, 2026 at 5:41 pm

    I think a combination of XML serialization and schema inference is probably all that you need.

    The XmlSerializer should be good enough to generate the XML file that you’re looking for. You really don’t need to do anything besides pass in the stream or stream writer, and the instance of the root-level entity. The actual code for XML serialization is 2 lines:

    // for example:
    public static void Serialize<T> (T data, TextWriter writer)
    {
        var xs = new XmlSerializer(typeof(T))
        xs.Serialize(writer, data);  // write out the xml to the stream writer...
    }
    

    I’m not sure why you want to avoid XML serialization.

    In order to save the XSD relative to the set of entities, you can infer the schema from the generated XML. Schema inference is done by using the XmlSchemaInference class in conjunction with XmlSchemaSet.

    I usually create a small schema inference utility for myself wherever I go, it looks like this:

    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Nothing to do.");
                return;
            }
    
            // first arg should contain the path to xml else error
            Console.WriteLine("Inferring schema of: {0}", args[0]);
    
            // default output should be xml name part + .xsd
            InferSchema(args[0]);
        }
    
        static void InferSchema(string fileName)
        {
            XmlWriter writer = null;
            XmlSchemaInference infer = new XmlSchemaInference();
            XmlSchemaSet sc = new XmlSchemaSet();
    
            string outputXsd = fileName.Replace(".xml", ".xsd");
            sc = infer.InferSchema(new XmlTextReader(fileName));
    
            using (writer = 
                XmlWriter.Create(new StreamWriter(outputXsd)))
            {
                foreach(XmlSchema schema in sc.Schemas())
                {
                    schema.Write(writer);
                    Console.WriteLine(">> found schema - generated to {0}", 
                        outputXsd);
                }
            }
        }
    }
    

    It doesn’t get any simpler than that.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.