We have the following XML schema: there's a root element (Response) with of a
single child element (Result).
----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="TaskRequest "
targetNamespace ="http://xyz.com/TaskResponse/1.0"
elementFormDefa ult="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
xmlns:mstns="ht tp://xyz.com/TaskResponse/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexTy pe name="Result">
<xs:sequence>
<xs:any minOccurs="1" maxOccurs="unbo unded" />
</xs:sequence>
<xs:attribute name="TaskNumbe r" type="xs:int" use="required" />
</xs:complexType>
<xs:element name="Response" >
<xs:complexType >
<xs:sequence>
<xs:element name="Result" type="Result"
maxOccurs="unbo unded" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
----------------------------------------------------------------------------------------------
We generated a VB wrapper class of this schema using the XSD.exe tool:
----------------------------------------------------------------------------------------------
'
'This source code was auto-generated by xsd, Version=2.0.406 07.85.
'
'''<remarks/>
<System.Seriali zableAttribute( ), _
System.Xml.Seri alization.XmlTy peAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0"), _
System.Xml.Seri alization.XmlRo otAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0", IsNullable:=fal se)> _
Public Class Response
Private resultField() As Result
'''<remarks/>
<System.Xml.Ser ialization.XmlE lementAttribute ("Result")> _
Public Property Result() As Result()
Get
Return Me.resultField
End Get
Set
Me.resultField = value
End Set
End Property
End Class
'''<remarks/>
<System.Seriali zableAttribute( ), _
System.Xml.Seri alization.XmlTy peAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0")> _
Public Class Result
Private anyField() As System.Xml.XmlE lement
Private taskNumberField As Integer
'''<remarks/>
<System.Xml.Ser ialization.XmlA nyElementAttrib ute()> _
Public Property Any() As System.Xml.XmlE lement()
Get
Return Me.anyField
End Get
Set
Me.anyField = value
End Set
End Property
'''<remarks/>
<System.Xml.Ser ialization.XmlA ttributeAttribu te()> _
Public Property TaskNumber() As Integer
Get
Return Me.taskNumberFi eld
End Get
Set
Me.taskNumberFi eld = value
End Set
End Property
End Class
----------------------------------------------------------------------------------------------
Note that the namespace http://xyz.com/TaskResponse/1.0 is correctly applied
to both classes Response and Result.
Serializing an instance of Response class (defined as root element in the
schema) we can obtain an XML document that correctly shows the namespace
http://xyz.com/TaskResponse/1.0.
Serializing an instance of the Result class (defined as child element in the
schema) the namespace is missing from generated XML document.
Why does the namespace is not declared in the xml file resulting form the
Result serialization?
Thanks for the help!