472,101 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Missing namespace in XML serialization

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"
elementFormDefault="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
xmlns:mstns="http://xyz.com/TaskResponse/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Result">
<xs:sequence>
<xs:any minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="TaskNumber" type="xs:int" use="required" />
</xs:complexType>
<xs:element name="Response">
<xs:complexType>
<xs:sequence>
<xs:element name="Result" type="Result"
maxOccurs="unbounded" 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.40607.85.

'

'''<remarks/>

<System.SerializableAttribute(), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0"), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0", IsNullable:=false)> _

Public Class Response

Private resultField() As Result

'''<remarks/>

<System.Xml.Serialization.XmlElementAttribute("Res ult")> _

Public Property Result() As Result()

Get

Return Me.resultField

End Get

Set

Me.resultField = value

End Set

End Property

End Class

'''<remarks/>

<System.SerializableAttribute(), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://xyz.com/TaskResponse/1.0")> _

Public Class Result

Private anyField() As System.Xml.XmlElement

Private taskNumberField As Integer

'''<remarks/>

<System.Xml.Serialization.XmlAnyElementAttribute() > _

Public Property Any() As System.Xml.XmlElement()

Get

Return Me.anyField

End Get

Set

Me.anyField = value

End Set

End Property

'''<remarks/>

<System.Xml.Serialization.XmlAttributeAttribute( )> _

Public Property TaskNumber() As Integer

Get

Return Me.taskNumberField

End Get

Set

Me.taskNumberField = 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!
Nov 12 '05 #1
0 1591

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Peter Theill | last post: by
1 post views Thread by MattBell | last post: by
1 post views Thread by saliwen | last post: by
1 post views Thread by Eric | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.