[3.0/LINQ] f3 invisible chars inserted into xml?
1)
http://i43.tinypic.com/669so1.png
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!");
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?
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
I am using utf8
? "if you're" ?
Re: [3.0/LINQ] f3 invisible chars inserted into xml?
Quote:
Originally Posted by Crash893
1)
http://www.vbforums.com/images/ieimages/2009/01/1.png
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.