I have a schema and have used XSDObjectGen.exe to create a set of
classes that represent the schema.
What is the best way to fill xsdobjectgen.exe generated classes with
data? I want to create and serialize an instance of one of the classes
in this schema. the class is declared publicly, but isn't accessible
outside the namespace:
<XmlType(TypeName:="BusinessProperty571LFormsType" ,Namespace:=Declarations.SchemaVersion),XmlRoot,Se rializable,
_
EditorBrowsable(EditorBrowsableState.Advanced)> _
Public Class BusinessProperty571LFormsType
The cause seems to be the XmlType attribute, if I remove it, the class
is accessible. How is this happening? all I want to do is say
something like:
bf = new sdr.BusinessProperty571LFormsType
bf.foo = "some data"
....
but I can't instanciate it.
Secondly, how do you serialize xsdobjectgen.exe class instances?
I'm trying to serialize one of the classes that is visible as a test:
<XmlRoot(ElementName:="SDR",Namespace:=Declaration s.SchemaVersion,IsNullable:=False),Serializable>
_
Public Class SDR
Here is the code:
Dim tmp As sdr.SDR
tmp = New sdr.SDR
Dim bs As System.Xml.Serialization.XmlSerializer
bs = New System.Xml.Serialization.XmlSerializer(GetType(sdr .SDR))
bs.Serialize(System.IO.File.Create("d:/tmp.xml"), tmp)
Here is the exception I get:
Unhandled Exception: System.InvalidOperationException: There was an
error reflecting type 'VisualBasicSax2.sdr.SDR'. --->
System.InvalidOperationException: There was an error reflecting field
'__SDRHeader'. ---> System.InvalidOperationException: There was an
error reflecting type 'VisualBasicSax2.sdr.SDRHeaderType'. --->
System.InvalidOperationException: There was an error reflecting field
'__FilerContacInfo'. ---> System.InvalidOperationException: There was
an error reflecting type 'VisualBasicSax2.sdr.ContactInfoType'. --->
System.InvalidOperationException: There was an error reflecting field
'__FullName'. ---> System.InvalidOperationException: There was an
error reflecting type 'System.String'. --->
System.InvalidOperationException: Value 'SDRStringType' cannot be used
for the XmlElementAttribute.DataType property. The datatype
'http://www.w3.org/2001/XMLSchema:SDRStringType' is missing.
SDRStringType is defined in the schema:
<xs:simpleType name="SDRStringType">
<xs:restriction base="xs:string">
<xs:pattern value="^[a-zA-Z0-9\s.\-/_']+$"/>
</xs:restriction>
</xs:simpleType>
Is this a bug in XSDObjectGen? Or do I need to pass the schema to the
serializer somehow?
Thanks in advance,
Aaron