need to construct your own byte array from a defiined XSD ? heres how
we use XSD tool
- go to Visual studio command prompt
- Go to path of xsd file(I.E c:\xsd)
- xsd [file name].xsd /c /n:[namespace]
- where
- /c – generate classes
- /n - namespace
Now you have created the class representation of the XML (or XSD) file.
you can now use this 2 functions to serialize and deserialize the objects , to byte array and from byte array
public static byte[] ObjectToXmlBytes(object o)enjoy
{
MemoryStream memoryStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(o.GetType());
serializer.Serialize(memoryStream, o);
return memoryStream.ToArray();
}
public static object XmlBytesToObject(byte[] bytes, Type t)
{
MemoryStream memoryStream = new MemoryStream(bytes);
memoryStream.Position = 0;
XmlSerializer serializer = new XmlSerializer(t);
return serializer.Deserialize(memoryStream);
}
0 תגובות:
Post a Comment