Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:09:12+00:00 2026-06-12T21:09:12+00:00

Hi I am trying to save xml to a file and it keeps adding

  • 0

Hi I am trying to save xml to a file and it keeps adding different character at the start of file.

Code I have is

string strCXML2;

strCXML2 = "<input type=" + "\"" + "hidden" + "\"" + " name=" + "\"" + "cxml-urlencoded" + "\"" + " value=" + "\"";
strCXML2 = strCXML2 + "<!DOCTYPE cXML SYSTEM " + "\"" + "http://xml.cxml.org/schemas/cXML/1.2.023/cXML.dtd" + "\"" + ">";

//<snip>

BinaryWriter bw5 = new BinaryWriter(File.Open(Server.MapPath("~/data/test/test19.xml"), FileMode.OpenOrCreate))   
bw5.Write(strCXML2); 
bw5.Close();

This return following file in xml “}” at start each time it is some other junk character

}<input type="hidden" name="cxml-urlencoded" value="<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.023/cXML.dtd">

Any ideas why it is doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:09:13+00:00Added an answer on June 12, 2026 at 9:09 pm

    The characters it is writing is the encoded length of the string, because: it is not expecting to write a text file. BinaryWriter writes… binary. It is writing the string in an encoded binary way that it can read back with BinaryReader.ReadString.

    Instead, use just:

    File.WriteAllText(path, strCXML2);
    

    The BinaryWriter.Write(string) method’s documentation explains all this:

    A length-prefixed string represents the string length by prefixing to the string a single byte or word that contains the length of that string. This method first writes the length of the string as a UTF-7 encoded unsigned integer, and then writes that many characters to the stream by using the BinaryWriter instance’s current encoding.

    and, helpfully, links to a separate section about writing text files

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to save a xml file as a string in clob type
i'm trying to save information gathered about the local computer to an XML-file. Everything
I am trying to save an xml document, and I have been trying to
I have noticed two different approaches to writing out data to an XML file
I'm trying to save data to and XML file on Iphone. For that, I
I am not trying to save dataset or datatable to a xml file rather
Hello there im trying to save some data from dynamic textboxes into XML file.
I'm trying to save an XML file encoded as UTF-16 with cElementTree. This is
Im trying to save some data into a xml file using the following PHP
I'm trying to write on xml file. but my server have DOM as disabled.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.