Results 1 to 13 of 13

Thread: [RESOLVED] [2.0] Small problem converting XML linebreaks into textboxes

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Resolved [RESOLVED] [2.0] Small problem converting XML linebreaks into textboxes

    Problem:

    I'm saving the contents of a multiline textbox to an XML file but when I try to read that XML file it's inserting the actual character for a linebreak rather than creating a line break (it shows a square).

    If I open the XML file in notepad it's showing the true line break like it should.

    How do I fix this so my textboxes also show the true line break?
    Last edited by ThisIsMyUserName; Aug 11th, 2006 at 07:10 AM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Do you have the "Multilines" property enabled for your text-boxes?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    I'm saving the contents of a multiline textbox
    Yes.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Anyone have a clue why this would happen? I'm using standard serialization on the XML file. I google'd/MSDN'd everything I could think of and no luck.

    The contents of the XML tag are being stored into string variables before they are put in the textbox as well.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    I don't know about a real solution
    But you can go for a work-around:
    "when you read the string from the XML file, replace all of the unknown char occurrences with line breaks"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Tried that before posting.

    It's on drugs. The square is actually a carriage return according to ultra edit's "character property" feature (unless ultraedit is converting the unknown char to a valid CR automatically). Character #13.

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Are you storing it as CDATA in the XML file?

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Nope, here's the code I'm using:

    Reading the XML file:
    Code:
            public Settings Load()
            {
                Settings settings = new Settings();
                
                if (File.Exists(SettingsPath))
                {
                    try
                    {
                        using (FileStream fs = new FileStream(SettingsPath, FileMode.Open))
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(Settings));
    
                            settings = (Settings)xs.Deserialize(fs);
    
                            fs.Close();
                        }
                    }
                    catch (Exception e)
                    {
                        {
                            if (MessageBox.Show("Error:\r\n" + e.Message, "Error reading settings file", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                            {
                                if (File.Exists(SettingsPath)) File.Delete(SettingsPath);
                            }
                            else
                            {
                                Environment.Exit(-1);
                            }
                        }
                    }
                }
                
                return settings;
            }
    Writing the XML file:
    Code:
            public void Save(Settings settings)
            {
                try
                {
                    using (FileStream fs = new FileStream(SettingsPath, FileMode.Create))
                    {
                        XmlSerializer xs = new XmlSerializer(typeof(Settings));
    
                        xs.Serialize(fs, settings);
    
                        fs.Close();
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error:\r\n" + e.Message, "Error writing settings file", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK);
                }
    
            }
    "Settings" is the name of my class that has this code. It's consisted of a few static structs which get stored in the XML file.

    For displaying the values, I'm just using standard code.

    On text change I'm saving the contents of the textbox to a string variable within the struct. Then when the program closes I'm saving all the contents of each struct to the XML file.
    Last edited by ThisIsMyUserName; Aug 15th, 2006 at 05:31 PM.

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Last bump. I've pretty much given up, and since it's on the 2nd page maybe someone else who had this problem didn't get a chance to see it.

  10. #10
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    saving to xml i did this by changing \n to <br>. Retreive then put to textbox with mutiline replace <br> to \n

    Just try
    Popskie

  11. #11
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    VB Code:
    1. saving to xml i did this by changing \n to <br>. Retreive then put to textbox with mutiline replace <br> to \n

    sorry i thought it is asp.net forums.

  12. #12

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Small problem converting XML linebreaks into textboxes

    Yep, seems the textbox control is a little picky with linebreak syntax.

    I had to change \n into \r\n when I read the file. \n by itself didn't work (tried this originally, under the assumption the square was an unknown char).

  13. #13
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [RESOLVED] [2.0] Small problem converting XML linebreaks into textboxes

    What control you used in displaying that text?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width