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

  • SEARCH
  • Home
  • 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 6054073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:06:42+00:00 2026-05-23T08:06:42+00:00

Seem to have some funny behaviour going on when I call the XMLTextWriter… XmlTextWriter

  • 0

Seem to have some funny behaviour going on when I call the XMLTextWriter…

XmlTextWriter writer = new XmlTextWriter(targetFileName, Encoding.UTF8);

writer.WriteValue("< ?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.WriteString(Environment.NewLine);
writer.WriteStartElement("video","UploadXsd");
writer.WriteString(Environment.NewLine);
    writer.WriteStartElement("title");
        writer.WriteString(Environment.NewLine);
        writer.WriteString(title);
        writer.WriteString(Environment.NewLine);
    writer.WriteEndElement();
    writer.WriteString(Environment.NewLine);
    writer.WriteStartElement("description");
    writer.WriteString(Environment.NewLine);
        writer.WriteString(description);
        writer.WriteString(Environment.NewLine);
    writer.WriteEndElement();
    writer.WriteString(Environment.NewLine);
    writer.WriteStartElement("contributor");
    writer.WriteString(Environment.NewLine);
        writer.WriteString(contributor);
        writer.WriteString(Environment.NewLine);
    writer.WriteEndElement();
    writer.WriteString(Environment.NewLine);
    writer.WriteStartElement("subject");
    writer.WriteString(Environment.NewLine);
        writer.WriteString(subject);
        writer.WriteString(Environment.NewLine);
    writer.WriteEndElement();
    writer.WriteString(Environment.NewLine);
writer.WriteEndElement();
writer.WriteString(Environment.NewLine);

writer.Flush();
writer.Close();

Then I see that it is creating this:

&lt; ?xml version="1.0" encoding="UTF-8"?&gt;
<video xmlns="UploadXsd">
<title>
MyTitle
</title>
<description>
MyDescription
</description>
<contributor>
MyContributor
</contributor>
<subject>
MySubject
</subject>
</video>

Why has the writer encoded the first element into Html but not the rest?, and more to the point how do I stop it doing this? I just want to create the first element.

  • 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-05-23T08:06:42+00:00Added an answer on May 23, 2026 at 8:06 am

    Do not use WriteValue() , it does the encoding. Use WriteProcessingInstruction instead.

    MSDN example:

    XmlWriter writer = XmlWriter.Create("output.xml");
    writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-16'");
    writer.WriteStartElement("root");
    writer.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have some weird issue going on that I am sure will
I have some colors that seem to come from a Delphi TColor variable (e.g
I have read through several reviews on Amazon and some books seem outdated. I
I always seem to have a hard time starting a new Firefox extension. Can
I seem to have some trouble overloading opIndexAssign in one of my classes. I
I seem to have some difficulty trying to use a href template tag. Here
I was looking into claimed identifiers, but they seem to have some issues with
I'm writing my own shell, and seem to have some kind of problem with
I seem to have some files in my Xcode project that I can't erase.
Sorry I saw similar questions but they don't seem to have some full answers

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.