By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,140 Members | 1,455 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,140 IT Pros & Developers. It's quick & easy. Deserializer and namepaces

P: 1
Hi all,
I have some XML that I am trying to deserialize using visual Basic 2010, I did not serialize the XML, I just want to deserialize it.

The issue I am having is that the element has a namespace of :q2 and a type of q2: and I am having a challenge in trying to reflect that in my code. An example of the XML is as follows:

Expand|Select|Wrap|Line Numbers
  1. <Record xmlns:q2="" xsi:type="q2:boats">
  2.         <q2:boats>
  3.           <q2:Command>call the captain</q2:Command>
  4.           <q2:Parameters>Microphone</q2:Parameters>
  5.           <q2:Type>Loud</q2:Type>
  6.           <q2:Order>117</q2:Order>
  7.         </q2:boats>
The class I created to store my data is as follows:

Expand|Select|Wrap|Line Numbers
  1. Partial Public Class Boats
  2.         Private mstrCommand As String
  3.         Private mstrParameters As String
  4.         Private mstrType As String
  5.         Private mstrOrder As String
  7.         Public Sub New()
  8.         End Sub
  10.         Public Sub New(ByVal Command As String, _
  11.                        ByVal Parameters As String, _
  12.                        ByVal Type As String, _
  13.                        ByVal Order As String)
  15.             Command = Command
  16.             Parameters = mstrParameters
  17.             Type = mstrType
  18.             Order = mstrOrder
  19.         End Sub
  21.         <XmlElement("q2:Command")> _
  22.         Public Property Command() As String
  23.             Get
  24.                 Return mstrCommand
  25.             End Get
  26.             Set(ByVal Value As String)
  27.                 mstrCommand = Value
  28.             End Set
  29.         End Property
  30.         <XmlElement("q2:Parameters")> _
  31.         Public Property Parameters() As String
  32.             Get
  33.                 Return mstrParameters
  34.             End Get
  35.             Set(ByVal Value As String)
  36.                 mstrParameters = Value
  37.             End Set
  38.         End Property
  40.         <XmlElement("q2:Type")> _
  41.         Public Property Type() As String
  42.             Get
  43.                 Return mstrType
  44.             End Get
  45.             Set(ByVal Value As String)
  46.                 mstrType = Value
  47.             End Set
  48.         End Property
  49.         <XmlElement("q2:Order")> _
  50.         Public Property Order() As String
  51.             Get
  52.                 Return mstrOrder
  53.             End Get
  54.             Set(ByVal Value As String)
  55.                 mstrOrder = Value
  56.             End Set
  57.         End Property
  58.     End Class
This will NOT work because there is no element called q2:command for example, so I have deserialization issues. How can I change my class to reflect the XML correctly?

I have seen some examples where people suggest that adding the namespace into a serializer will generate the q1: but there is nothing about how to deserialize it, especially when you did not serialize the XML in the first place :)

Any help would be much appreciated.
Jun 13 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.