Re: Array Serialization
From: Dino Chiesa [Microsoft] (dinoch_at_online.microsoft.com)
Date: 05/04/04
- Next message: Dino Chiesa [Microsoft]: "Re: .NET WebService method doesn't understand xsd list"
- Previous message: Dino Chiesa [Microsoft]: "Re: Consume Java Webservice through .NET client"
- In reply to: John Tear: "Array Serialization"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 3 May 2004 23:09:53 -0400
you are not serializing the array.
Your code is serializing N elements of the array, one at a time. Which is
why you get a stream with N xml documents, all concatenated together. The
concatenated result does not constitute a well formed xml doc, as you
pointed out.
Instead of serializing N array elements, serialize the entire array at once.
When you get the serializer, you should do
> Dim oXS As XmlSerializer = New XmlSerializer(GetType(App[]))
(I am not a vb guy so I do not know if that is legal syntax for "GetType".
but you get the idea)
Then
> oXS.Serialize(oStmW, marrApplications)
( no iteration ! )
-Dino
"John Tear" <johntear@hotmail.com> wrote in message
news:92ae3244.0405021128.10dd8302@posting.google.com...
> (Note I have posted to this group because I had no luck in
> microsoft.public.dotnet.vb.general)
>
> Hi all
>
> This is probably an easy one... I would like to serialize an array to
> an XML file but I cant quite get it right.
>
> Here goes
>
> I declare the array at the top of the class
>
> Private marrApplications(100) As App
>
> Then when I go to write the array...
>
> Private Sub save_Applications()
> 'serialize the object
> Dim oXS As XmlSerializer = New XmlSerializer(GetType(App))
> Dim oStmW As StreamWriter
> Dim i As Integer
>
> Try
> oStmW = New StreamWriter(Application.StartupPath.ToString&
> "\\Applications.xml")
>
>
> For i = 0 To m_applicationCount - 1
> oXS.Serialize(oStmW, marrApplications(i))
> Next
>
>
> oStmW.Close()
> Catch ex As Exception
> Debug.Write(ex.Message)
> End Try
> End Sub
>
> It sort of saves the array but it is not properly formed in XML. Here
> is the result...
>
> <?xml version="1.0" encoding="utf-8"?>
> <Class_App xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <Property_Name>Blah</Property_Name>
> <Property_ConnectionString>Blah</Property_ConnectionString>
> <Property_ConnectionCount>0</Property_ConnectionCount>
> <Property_MaxConnections>100</Property_MaxConnections>
> </Class_App><?xml version="1.0" encoding="utf-8"?>
> <Class_App xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <Property_Name>Blah</Property_Name>
> <Property_ConnectionString>Blah</Property_ConnectionString>
> <Property_ConnectionCount>0</Property_ConnectionCount>
> <Property_MaxConnections>100</Property_MaxConnections>
> </Class_App>
>
> I know this isnt right but what am I doing wrong?
>
> Any help will be much appreciated, thanks.
> John.
- Next message: Dino Chiesa [Microsoft]: "Re: .NET WebService method doesn't understand xsd list"
- Previous message: Dino Chiesa [Microsoft]: "Re: Consume Java Webservice through .NET client"
- In reply to: John Tear: "Array Serialization"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|