When I create an XML file using XmlSerializer and try to open it in excel, I get the following message:
The specified XML source does not refer to a schema. Excel will create a schema based on the XML source data.
Is there a way to include the schema in an XML file so that Excel (or any other program) does not need to be calculated?
Here is an example program showing how I create my XML file.
namespace Sandbox_Console { internal class Program { private static void Main() { List<MyClass> test = new List<MyClass>(); test.Add(new MyClass() { Name = "Test", Foo = "Shazam"}); test.Add(new MyClass() { Name = "Test2", Foo = "Shazam2" }); XmlSerializer ser = new XmlSerializer(typeof (List<MyClass>)); using (var file = new FileStream(@"C:\Users\srchamberlain\Desktop\test.xml", FileMode.Create)) { ser.Serialize(file, test); } } } public class MyClass { [XmlAttribute] public string Name { get; set; } [XmlElement] public string Foo { get; set; } } }
XML generated
<?xml version="1.0"?> <ArrayOfMyClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <MyClass Name="Test"> <Foo>Shazam</Foo> </MyClass> <MyClass Name="Test2"> <Foo>Shazam2</Foo> </MyClass> </ArrayOfMyClass>
In my real file, which I create the file size is larger than 300 MB, and it takes a lot of time to analyze the data, I hope that by providing a diagram this can reduce the time it takes to process the file.
source share