How to enable schema with xml

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.

+4
source share
2 answers

If you already have an XSD file, you can download it to Excel, and then install Excel to use this scheme in your file. Just follow this guide http://www.mrexcel.com/articles/using-xml-in-excel.php This way you can save the excel file as XML data and this is just confirmed by your schema.

0
source

XML, by its nature, is a fairly detailed syntax. Consider writing to CSV directly, or use XLSB through OLE. XLSB retains its own Excel formatting, but is a compact binary format that loads quickly.

0
source

Source: https://habr.com/ru/post/1492103/


All Articles