|
-
Jan 14th, 2009, 11:01 AM
#1
Thread Starter
Fanatic Member
[3.0/LINQ] f3 invisible chars inserted into xml?
1)

I'm not sure where they are coming from but its definitely made when i create the file.
I thought i was creating the xml correctly but now im not so sure
I assume that this is being created at line 9 but im not sure.
C# Code:
XmlDocument xmlDoc = new XmlDocument(); if (File.Exists(path)) { File.Delete(path); } //if file is not found, create a new xml file XmlTextWriter xmlWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); xmlWriter.WriteStartElement("Root"); xmlWriter.Close(); xmlDoc.Load(path); XmlNode root = xmlDoc.DocumentElement; XmlElement fileInfo = xmlDoc.CreateElement("FileInfo"); XmlElement MatchInfo = xmlDoc.CreateElement("MatchInfo"); XmlElement TeamInfo = xmlDoc.CreateElement("TeamInfo"); MatchInfo.SetAttribute("Headline", TB_Headline_o.Text); MatchInfo.SetAttribute("R1Title", TB_R1_Title_o.Text); MatchInfo.SetAttribute("R2Title", TB_R2_Title_o.Text); MatchInfo.SetAttribute("R3Title", TB_R3_Title_o.Text); MatchInfo.SetAttribute("R4Title", TB_R4_Title_o.Text); XmlElement TourName = xmlDoc.CreateElement("TourName"); XmlElement Username = xmlDoc.CreateElement("Username"); XmlElement Timestamp = xmlDoc.CreateElement("timestamp"); XmlElement Title = xmlDoc.CreateElement("Region"); (Cutting out alot of the middle stuff) root.AppendChild(fileInfo); root.AppendChild(MatchInfo); root.AppendChild(TeamInfo); xmlDoc.Save(path); MessageBox.Show("File Saved!");
-
Jan 14th, 2009, 11:43 AM
#2
Thread Starter
Fanatic Member
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
I found out this is called a BOM or byte order marker its part of the unicode standard.
I tried encodeing as ascii but i still get it ANy ideas?
-
Jan 14th, 2009, 03:12 PM
#3
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
-
Jan 15th, 2009, 01:00 PM
#4
Thread Starter
Fanatic Member
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
I am using utf8
? "if you're" ?
-
Jan 15th, 2009, 04:24 PM
#5
Frenzied Member
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
 Originally Posted by Crash893
1)
I'm not sure where they are coming from but its definitely made when i create the file.
I thought i was creating the xml correctly but now im not so sure
I assume that this is being created at line 9 but im not sure.
C# Code:
XmlDocument xmlDoc = new XmlDocument(); if (File.Exists(path)) { File.Delete(path); } //if file is not found, create a new xml file XmlTextWriter xmlWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); xmlWriter.WriteStartElement("Root"); xmlWriter.Close(); xmlDoc.Load(path); XmlNode root = xmlDoc.DocumentElement; XmlElement fileInfo = xmlDoc.CreateElement("FileInfo"); XmlElement MatchInfo = xmlDoc.CreateElement("MatchInfo"); XmlElement TeamInfo = xmlDoc.CreateElement("TeamInfo"); MatchInfo.SetAttribute("Headline", TB_Headline_o.Text); MatchInfo.SetAttribute("R1Title", TB_R1_Title_o.Text); MatchInfo.SetAttribute("R2Title", TB_R2_Title_o.Text); MatchInfo.SetAttribute("R3Title", TB_R3_Title_o.Text); MatchInfo.SetAttribute("R4Title", TB_R4_Title_o.Text); XmlElement TourName = xmlDoc.CreateElement("TourName"); XmlElement Username = xmlDoc.CreateElement("Username"); XmlElement Timestamp = xmlDoc.CreateElement("timestamp"); XmlElement Title = xmlDoc.CreateElement("Region"); (Cutting out alot of the middle stuff) root.AppendChild(fileInfo); root.AppendChild(MatchInfo); root.AppendChild(TeamInfo); xmlDoc.Save(path); MessageBox.Show("File Saved!");
Code:
XmlTextWriter xmlWriter = new XmlTextWriter(path, System.Text.Encoding.ASCII);
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='Ascii'");
XmlDocument uses the encoding found in the file.
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
|