|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XML Deserializer problemHave very strange issue with deserialization. Really need help, because i just don't getting why the hell this not works in a way it suppose to be. Here is the sample object i serialize into XML: <XmlRoot("CONTACTS")> _ Public Class Contacts <XmlAttribute("version")> Public Version As String = "0.2" <XmlElement(Type:=GetType(OrganizationType), ElementName:="ORGANIZATION", IsNullable:=False, Form:=XmlSchemaForm.Qualified), _ EditorBrowsable(EditorBrowsableState.Advanced)> _ Public __Organizations As OrganizationColectionType <XmlIgnore()> _ Public Property Organizations() As OrganizationColectionType Get If __Organizations Is Nothing Then __Organizations = New OrganizationColectionType() Organizations = __Organizations End Get Set(ByVal Value As OrganizationColectionType) __Organizations = Value End Set End Property End Class Deseriliazing i do via this function: Public Function SetXml(ByVal obj As Object, ByVal XmlData As String) As Object Dim ser As New XmlSerializer(obj.GetType) Dim ms As New IO.MemoryStream(Text.Encoding.UTF8.GetBytes(XmlData)) Dim xr As New Xml.XmlTextReader(ms) Debug.WriteLine("Can deserialize: " + ser.CanDeserialize(xr).ToString) Return ser.Deserialize(xr) End Function On ser.CanDeserialize it always return /TRUE/ that i assume tells that source XML is fine. At least it says "Gets a value that indicates whether this XmlSerializer can deserialize a specified XML document." on http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.candeserialize(VS.80).aspx But problem is that actual deserialization is never happens. Object not getting filled with data from XML. If i take any other object to deserialize, i get my data, but objects build like this are failed. Is anyone have any idea wtf is wrong? Cheers, Evi. Does the xml string look as you expect?
Show quoteHide quote "Skitsanos" wrote: > Guys, > > Have very strange issue with deserialization. Really need help, > because i just don't getting why the hell this not works in a way it > suppose to be. > > Here is the sample object i serialize into XML: > > <XmlRoot("CONTACTS")> _ > Public Class Contacts > <XmlAttribute("version")> Public Version As String = "0.2" > > <XmlElement(Type:=GetType(OrganizationType), > ElementName:="ORGANIZATION", IsNullable:=False, > Form:=XmlSchemaForm.Qualified), _ > EditorBrowsable(EditorBrowsableState.Advanced)> _ > Public __Organizations As OrganizationColectionType > > <XmlIgnore()> _ > Public Property Organizations() As OrganizationColectionType > Get > If __Organizations Is Nothing Then __Organizations = > New OrganizationColectionType() > Organizations = __Organizations > End Get > Set(ByVal Value As OrganizationColectionType) > __Organizations = Value > End Set > End Property > End Class > > Deseriliazing i do via this function: > > Public Function SetXml(ByVal obj As Object, ByVal XmlData As > String) As Object > Dim ser As New XmlSerializer(obj.GetType) > Dim ms As New > IO.MemoryStream(Text.Encoding.UTF8.GetBytes(XmlData)) > Dim xr As New Xml.XmlTextReader(ms) > Debug.WriteLine("Can deserialize: " + > ser.CanDeserialize(xr).ToString) > Return ser.Deserialize(xr) > End Function > > On ser.CanDeserialize it always return /TRUE/ that i assume tells that > source XML is fine. At least it says "Gets a value that indicates > whether this XmlSerializer can deserialize a specified XML document." > on http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.candeserialize(VS.80).aspx > > But problem is that actual deserialization is never happens. Object > not getting filled with data from XML. > > If i take any other object to deserialize, i get my data, but objects > build like this are failed. > > Is anyone have any idea wtf is wrong? > > Cheers, > Evi. > On Nov 26, 3:01 am, Family Tree Mike
<FamilyTreeM***@discussions.microsoft.com> wrote: > Does the xml string look as you expect? Yes, it looks very fine. The actual serialization output is this:<CONTACTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="0.2"> <ORGANIZATION name="Org1" shortName="org1"> <PERSON firstName="John" lastName="Doe" emailAddress="j***@local.vpn" /> </ORGANIZATION> <ORGANIZATION name="Org2" shortName="org2" /> </CONTACTS> "Skitsanos" wrote: What does your call to SetXml() look like? I'm guessing it looks like this, > Yes, it looks very fine. The actual serialization output is this: > > <CONTACTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="0.2"> > <ORGANIZATION name="Org1" shortName="org1"> > <PERSON firstName="John" lastName="Doe" > emailAddress="j***@local.vpn" /> > </ORGANIZATION> > <ORGANIZATION name="Org2" shortName="org2" /> > </CONTACTS> > but I don't want to assume that it does: Contact2 = SetXml(Contact1, theXmlString) ' note, contact1 is not changed in this call, only used to get the data type. On 26 Noi, 13:40, Family Tree Mike
<FamilyTreeM***@discussions.microsoft.com> wrote: > What does your call to SetXml() look like? I'm guessing it looks like this, damn, im the one who screwed it;) thanx man. i just didn't paid enough> but I don't want to assume that it does: > > Contact2 = SetXml(Contact1, theXmlString) ' note, contact1 is not changed > in this call, only used to get the data type. attention to my own code, silly.
Removing reference type members from a generic list clone
vs2008 or not Creating a Web Service (Service, not Client) from WSDL Reurning Arrays Question about Application Layout Saving an image from a picturebox Editing an indexed PixelFormat Where are use scoped settings stored? working with a com interface Color Equality |
|||||||||||||||||||||||