Empty xmlns issue

MattP

Well-known member
Joined
Feb 29, 2008
Messages
1,206
Location
WY, USA
Programming Experience
5-10
I'm converting the Strokes collection from a Silverlight InkPresenter to xml so I can save it in an nvarchar(MAX) column in a SQL database.

Everything works correctly except in every <Stroke> tag I get an empty xmlns which blows up the XamlReader when I'm trying to load it.

I've gotten around the empty xmlns by doing a String.Replace before I return but this just screams 'you're doing it wrong!'

If anyone has any insight to the correct way of resolving this it would be appreciated.

VB.NET:
    Private Function StrokesToXaml(ByVal presenter As InkPresenter) As String
        Dim doc = <?xml version="1.0" encoding="utf-16"?>
                  <StrokeCollection xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
                      <%= From stroke In presenter.Strokes _
                          Select <Stroke>
                                     <Stroke.DrawingAttributes>
                                         <DrawingAttributes Width=<%= stroke.DrawingAttributes.Width.ToString() %>
                                             Height=<%= stroke.DrawingAttributes.Height.ToString() %>
                                             Color=<%= String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", _
                                                       stroke.DrawingAttributes.Color.A, _
                                                       stroke.DrawingAttributes.Color.R, _
                                                       stroke.DrawingAttributes.Color.G, _
                                                       stroke.DrawingAttributes.Color.B) %>
                                             OutlineColor=<%= String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", _
                                                              stroke.DrawingAttributes.OutlineColor.A, _
                                                              stroke.DrawingAttributes.OutlineColor.R, _
                                                              stroke.DrawingAttributes.OutlineColor.G, _
                                                              stroke.DrawingAttributes.OutlineColor.B) %>/>
                                     </Stroke.DrawingAttributes>
                                     <Stroke.StylusPoints>
                                         <StylusPointCollection>
                                             <%= From sp In stroke.StylusPoints _
                                                 Select <StylusPoint X=<%= sp.X.ToString() %> Y=<%= sp.Y.ToString() %>/> %>
                                         </StylusPointCollection>
                                     </Stroke.StylusPoints>
                                 </Stroke> %>
                  </StrokeCollection>

        Dim sw As New IO.StringWriter
        doc.Save(sw)
        Return sw.GetStringBuilder().ToString().Replace(" xmlns=" & ControlChars.Quote & ControlChars.Quote, "")
    End Function
 
Back
Top