c# - .Net XML Serialization based on an XSD? -


I am serialising and deserialising .net objects without any problem using the XmlSerializer class, although now let us see Someone else wants to do some analysis on that data.

To help with this, we have built XSD based on our class: xsd.exe / t: DataClass Assembly.exe

The beginning of XSD looks like this:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xs: schema elementfirm = default "xmlns: xs =" http://www.w3.org/2001/XMLSchema "& gt; & Lt; Xs: element name = "data class" nilibble = "true" type = "data class" /> & Lt; X: complex type name = "data class" & gt; & Lt; X: complex content mixed = "wrong" & gt; & Lt; Xs: extension base = "BaseDataClass" & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element minOccurs = "0" maxOccurs = "1" name = "StudyID" type = "xs: string" /> & Lt; Xs: element minOccurs = "1" maxOccurs = "1" name = "status" type = "x :: int" /> & Lt; Xs: element minOccurs = "1" maxOccurs = "1" name = "IViewer" type = "x: string" />  

The XML is created in this way (where obj is an example of our dataclass):

  as new XML Serializer (obj.GetType) Dim Xs Dim xmlTextWriter as the new XMLTextwer (MemoryStream, Encoding.Utf 8) xs.Serialize (xmlTextWriter, obj)  

... which looks like XML:

  & lt;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Dataclass xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd = "http://www.w3.org/2001/XMLSchema" & gt; & Lt; Version & gt; SixMonthQ-E1 & lt; / Version & gt; & Lt; IViewer xsi: nil = "true" /> & Lt; Language xsi: nil = "true" /> ... & lt; Study ID & gt; 12345 & lt; / StudyID & gt;  

Oddly generated XML does not follow XSD generated from the same category.

My question is, is there a way to tell XmlSerializer that the object is serial based on a given XSD?

On one side, I have looked at other ways of deciding it: I have tried to regenerate sections from XSD generated - this is the only problem. I can explicitly tell the order of elements using the XML Element feature, but I am doing this for 400+ public properties.

No, sorry. It does not seem that by any means the XmlSerializer can be compelled to take the schema into account.

XSD.XA and Rev. Roundtrip conversion to sections using that schema.

  xsd.exe data class. Xsd / classes / language: cs  

At least this may give you some insight. There was a problem with the XSD.exe command in the original classes.

In addition to this option, XSD:


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -