Click here to Skip to main content
15,944,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
while saving my textbox data to the xml file I have getting the error

Invalid name character in 'sdf f'. The ' ' character, hexadecimal value 0x20, cannot be included in a name.

Here is my code

Private Sub Cmd_Save_As_XML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmd_Save_As_XML.Click

        Dim settings As New XmlWriterSettings()
        settings.Indent = True

        ' Initialize the XmlWriter.
        Dim XmlWrt As XmlWriter = XmlWriter.Create("C:\00temp\GoogleEarth_VaneTest.xml", settings)

        With XmlWrt

            ' Write the Xml declaration.

            ' Write a comment.
            .WriteComment("XML Database.")

            ' Write the root element.




            ' Start our first lookat.

            ' The lookat nodes.








            ' The end of this lookat.



            ' Start our first point.


            .WriteString(Txt_Longitude.Text.ToString() + Txt_Latitude.Text.ToString() + Txt_Altitude.Text.ToString())

            ' The end of this point.

            ' Close the XmlTextWriter.

        End With

        MessageBox.Show("XML file saved successfully. In C:\00temp\")

    End Sub

Please Guide

once the textbox value is with space for example ben singh it may thows erros as mentioned above.
[no name] 3-Nov-14 7:15am    
Yes, it will throw error. You're trying to create an element with a name that has spaces, and that's not valid in XML. Element names can't contain spaces.
Bensingh 3-Nov-14 7:19am    
is it any solution for this

1 solution

Convert all spaces to underscore characters:
mystring = mystring.Replace(" ", "_");
If you do this whenever you are handling user input and reverse it on presentation back, the user won't even notice the difference!
Share this answer
[no name] 3-Nov-14 7:25am    
Yeah!! was about to suggest that as a solution !
Good one :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900