c# - How to include the schema with the xml -
when create xml file using xmlserializer , attempt open in excel following message:
the specified xml source not refer schema. excel create schema based on xml source data. is there way include schema in xml file excel (or other program) not need calculate it?
here example program showing how creating 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; } } } the generated xml
<?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 real file generating file size on 300 mb large , taking long time data parsed out, hope providing schema can decrease time takes process file.
if have xsd file can load excel, set excel use schema file. follow guide http://www.mrexcel.com/articles/using-xml-in-excel.php in way can save excel file xml data, , validated schema.
Comments
Post a Comment