Silverlight XmlReader Issue

I was making a Silverlight 3 application in Visual Studio 2008. The code was suppose to open a Stream object and read it using an XmlReader. The code compiled and ran but for some reason it seemed like only some of the XML nodes were being read. After spending two hours tracking to fix this problem I stunned to learn what the issue was. The Silverlight XmlReader does not reliably read XML nodes if they are on the same line. To reliably read the XML nodes, the XML has to be formatted so that child nodes are on a new line. For example, was not being reliably read. Sometimes the reader would only read one child element. However, if you format the XML like the following then the XmlReader would work reliably.

The Silverlight code I was using to read the XML was the following.

Dim stream As New StringReader(data)
Dim reader As XmlReader = XmlReader.Create(stream)
While reader.ReadToFollowing(“Stroke”)
If reader.NodeType = XmlNodeType.Element Then
If reader.Name = “Stroke” Then
‘Do something
End If
End If
End While



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s