c# - DataContractSerializer not deserializing all variables -


i'm trying deserialize xml without having original class used create object in xml. class called comopcclientconfiguration.
it's succesfully setting serverurl , serverurlhda values, not rest of them...
i'm asking is: how can make rest of these values set properly, , why aren't working current code.

here deserialization code:
conf xelement represents comclientconfiguration xml

datacontractserializer ser = new datacontractserializer(typeof(comclientconfiguration), new type[] {typeof(comclientconfiguration), typeof(comopcclientconfiguration) }); comopcclientconfiguration config = (comopcclientconfiguration)ser.readobject(conf.createreader()); 

i don't know why have have comclientconfiguration , comopcclientconfiguration, there's better way known types hack have. it's have.

here xml looks in file.

<comclientconfiguration  xsi:type="comopcclientconfiguration" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">    <serverurl>the url</serverurl>    <servername>a server name   </servername>    <servernamespaceurl>a namespace url</servernamespaceurl>     <maxreconnectwait>5000</maxreconnectwait>     <maxreconnectattempts>0</maxreconnectattempts>     <fastbrowsing>true</fastbrowsing>    <itemidequaltoname>true</itemidequaltoname>    <serverurlhda>hda url</serverurlhda>  </comclientconfiguration> 

here class built deserialize into:

[datacontract(name = "comclientconfiguration", namespace = "http://opcfoundation.org/ua/sdk/cominterop")] public class comclientconfiguration {     public comclientconfiguration() { }      //prog-id da-connection     [datamember(name = "serverurl"), optionalfield]     public string serverurl;//url     [datamember(name = "servername")]     public string servername;     [datamember(name = "servernamespaceurl")]     public string servernamespaceurl;//url     [datamember(name = "maxreconnectwait")]     public int maxreconnectwait;     [datamember(name = "maxreconnectattempts")]     public int maxreconnectattempts;     [datamember(name = "fastbrowsing")]     public bool fastbrowsing;     [datamember(name = "itemidequaltoname")]     public bool itemidequaltoname;      //progid da-connection     [datamember, optionalfield]     public string serverurlhda;//url } 

i additionally had make class, it's same different name. used known types in serializer because don't know how whole type naming stuff works.

[datacontract(name = "comopcclientconfiguration", namespace = "http://opcfoundation.org/ua/sdk/cominterop")] public class comopcclientconfiguration {     public comopcclientconfiguration() { }      ... same innards comclientconfiguration } 

data-contract-serializer is... fussy. in particular, wonder if element order problem here. however, not best tool working xml. xmlserializer more robust here - can handle better range of xml. dcs isn't intended it's primary goal.

with simple xml don't need attributes etc. can use xsd.exe on existing xml generate matching c# classes (in 2 steps; xml-to-xsd; xsd-to-c#).


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -