Results 1 to 5 of 5

Thread: [3.0/LINQ] f3 invisible chars inserted into xml?

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    [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:
    1. XmlDocument xmlDoc = new XmlDocument();
    2.             if (File.Exists(path))
    3.             {
    4.                 File.Delete(path);
    5.             }
    6.             //if file is not found, create a new xml file
    7.             XmlTextWriter xmlWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8);
    8.             xmlWriter.Formatting = Formatting.Indented;
    9.             xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
    10.             xmlWriter.WriteStartElement("Root");
    11.  
    12.             xmlWriter.Close();
    13.             xmlDoc.Load(path);
    14.  
    15.             XmlNode root = xmlDoc.DocumentElement;
    16.  
    17.             XmlElement fileInfo = xmlDoc.CreateElement("FileInfo");
    18.             XmlElement MatchInfo = xmlDoc.CreateElement("MatchInfo");
    19.             XmlElement TeamInfo = xmlDoc.CreateElement("TeamInfo");
    20.  
    21.  
    22.             MatchInfo.SetAttribute("Headline", TB_Headline_o.Text);
    23.             MatchInfo.SetAttribute("R1Title", TB_R1_Title_o.Text);
    24.             MatchInfo.SetAttribute("R2Title", TB_R2_Title_o.Text);
    25.             MatchInfo.SetAttribute("R3Title", TB_R3_Title_o.Text);
    26.             MatchInfo.SetAttribute("R4Title", TB_R4_Title_o.Text);
    27.  
    28.             XmlElement TourName = xmlDoc.CreateElement("TourName");
    29.             XmlElement Username = xmlDoc.CreateElement("Username");
    30.             XmlElement Timestamp = xmlDoc.CreateElement("timestamp");
    31.             XmlElement Title = xmlDoc.CreateElement("Region");
    32.  
    33.  
    34.  
    35. (Cutting out alot of the middle stuff)
    36.  
    37.  
    38.  
    39.             root.AppendChild(fileInfo);
    40.             root.AppendChild(MatchInfo);
    41.             root.AppendChild(TeamInfo);
    42.             xmlDoc.Save(path);
    43.             MessageBox.Show("File Saved!");

  2. #2

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    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?

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [3.0/LINQ] f3 invisible chars inserted into xml?

    Try UTF8 if you're

  4. #4

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: [3.0/LINQ] f3 invisible chars inserted into xml?

    I am using utf8


    ? "if you're" ?

  5. #5
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [3.0/LINQ] f3 invisible chars inserted into xml?

    Quote 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:
    1. XmlDocument xmlDoc = new XmlDocument();
    2.             if (File.Exists(path))
    3.             {
    4.                 File.Delete(path);
    5.             }
    6.             //if file is not found, create a new xml file
    7.             XmlTextWriter xmlWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8);
    8.             xmlWriter.Formatting = Formatting.Indented;
    9.             xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
    10.             xmlWriter.WriteStartElement("Root");
    11.  
    12.             xmlWriter.Close();
    13.             xmlDoc.Load(path);
    14.  
    15.             XmlNode root = xmlDoc.DocumentElement;
    16.  
    17.             XmlElement fileInfo = xmlDoc.CreateElement("FileInfo");
    18.             XmlElement MatchInfo = xmlDoc.CreateElement("MatchInfo");
    19.             XmlElement TeamInfo = xmlDoc.CreateElement("TeamInfo");
    20.  
    21.  
    22.             MatchInfo.SetAttribute("Headline", TB_Headline_o.Text);
    23.             MatchInfo.SetAttribute("R1Title", TB_R1_Title_o.Text);
    24.             MatchInfo.SetAttribute("R2Title", TB_R2_Title_o.Text);
    25.             MatchInfo.SetAttribute("R3Title", TB_R3_Title_o.Text);
    26.             MatchInfo.SetAttribute("R4Title", TB_R4_Title_o.Text);
    27.  
    28.             XmlElement TourName = xmlDoc.CreateElement("TourName");
    29.             XmlElement Username = xmlDoc.CreateElement("Username");
    30.             XmlElement Timestamp = xmlDoc.CreateElement("timestamp");
    31.             XmlElement Title = xmlDoc.CreateElement("Region");
    32.  
    33.  
    34.  
    35. (Cutting out alot of the middle stuff)
    36.  
    37.  
    38.  
    39.             root.AppendChild(fileInfo);
    40.             root.AppendChild(MatchInfo);
    41.             root.AppendChild(TeamInfo);
    42.             xmlDoc.Save(path);
    43.             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
  •  



Click Here to Expand Forum to Full Width