|
-
Aug 11th, 2006, 06:53 AM
#1
Thread Starter
Member
[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.
-
Aug 11th, 2006, 09:45 AM
#2
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
-
Aug 11th, 2006, 02:00 PM
#3
Thread Starter
Member
Re: [2.0] Small problem converting XML linebreaks into textboxes
I'm saving the contents of a multiline textbox
Yes.
-
Aug 12th, 2006, 05:11 PM
#4
Thread Starter
Member
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.
-
Aug 12th, 2006, 05:15 PM
#5
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
-
Aug 12th, 2006, 05:51 PM
#6
Thread Starter
Member
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.
-
Aug 14th, 2006, 01:08 PM
#7
Re: [2.0] Small problem converting XML linebreaks into textboxes
Are you storing it as CDATA in the XML file?
-
Aug 15th, 2006, 05:27 PM
#8
Thread Starter
Member
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.
-
Aug 22nd, 2006, 12:17 AM
#9
Thread Starter
Member
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.
-
Aug 24th, 2006, 04:30 AM
#10
Fanatic Member
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
-
Aug 24th, 2006, 04:35 AM
#11
Fanatic Member
Re: [2.0] Small problem converting XML linebreaks into textboxes
VB Code:
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.
-
Aug 24th, 2006, 03:32 PM
#12
Thread Starter
Member
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).
-
Aug 24th, 2006, 09:33 PM
#13
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|