Click here to Skip to main content
16,012,025 members
Home / Discussions / C#
   

C#

 
AnswerRe: abstract classes Pin
Hamid_RT17-May-08 7:22
Hamid_RT17-May-08 7:22 
Questionnotification Pin
ellllllllie16-May-08 1:38
ellllllllie16-May-08 1:38 
AnswerRe: notification Pin
originSH16-May-08 1:39
originSH16-May-08 1:39 
AnswerRe: notification Pin
Pete O'Hanlon16-May-08 2:06
mvePete O'Hanlon16-May-08 2:06 
Questionproblems in checklistbox Pin
Amitava Dutta16-May-08 1:05
Amitava Dutta16-May-08 1:05 
AnswerRe: problems in checklistbox Pin
Christian Wikander16-May-08 2:25
Christian Wikander16-May-08 2:25 
QuestionHow can i read print content (print document data) from a Job using PrintQueueStream [modified] Pin
Krishna Prasad RVS16-May-08 0:38
Krishna Prasad RVS16-May-08 0:38 
QuestionXML encoding issue Pin
George_George16-May-08 0:11
George_George16-May-08 0:11 
Hello everyone,


Here is my code, and it will always output UTF-16 at XML header even if I set the XML declaration to UTF-8.

Here is my code and output.

My questions,

1. How to make UTF-8 in header other than UTF-16?
2. Is the XML string really UTF-16 encoded or UTF-8 encoded? I think in C#, string is always UTF-16 encoded, why do we need a UTF-8 in header?

<?xml version="1.0" encoding="utf-16"?>
<CategoryList a="12345" b="1d5458cd-a070-40cc-a3f4-cf3c394013cc" c="true" />

using System;
using System.Text;
using System.IO;
using System.Xml;

class Test
{
    public static void Main()
    {
        XmlDocument xmlDoc = new XmlDocument();


        // Write down the XML declaration
        XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

        // Create the root element
        XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
        xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
        // Set attribute name and value!
        rootNode.SetAttribute("a", "12345");
        rootNode.SetAttribute("b", Guid.NewGuid().ToString());
        rootNode.SetAttribute("c", "true");
        xmlDoc.AppendChild(rootNode);

        // Save to the XML file
        StringWriter stream = new StringWriter();
        xmlDoc.Save(stream);
        string content = stream.ToString();
        Console.Write(content);

        return;
    }
}



thanks in advance,
George
AnswerRe: XML encoding issue Pin
mlsteeves16-May-08 3:48
mlsteeves16-May-08 3:48 
GeneralRe: XML encoding issue Pin
George_George16-May-08 4:49
George_George16-May-08 4:49 
GeneralRe: XML encoding issue Pin
mlsteeves16-May-08 5:22
mlsteeves16-May-08 5:22 
GeneralRe: XML encoding issue Pin
George_George16-May-08 20:37
George_George16-May-08 20:37 
GeneralRe: XML encoding issue Pin
mlsteeves20-May-08 1:55
mlsteeves20-May-08 1:55 
GeneralRe: XML encoding issue Pin
George_George20-May-08 3:55
George_George20-May-08 3:55 
GeneralRe: XML encoding issue Pin
PIEBALDconsult16-May-08 5:52
mvePIEBALDconsult16-May-08 5:52 
GeneralRe: XML encoding issue Pin
George_George16-May-08 20:39
George_George16-May-08 20:39 
GeneralRe: XML encoding issue Pin
PIEBALDconsult17-May-08 4:01
mvePIEBALDconsult17-May-08 4:01 
GeneralRe: XML encoding issue Pin
George_George17-May-08 4:13
George_George17-May-08 4:13 
GeneralRe: XML encoding issue Pin
PIEBALDconsult17-May-08 7:58
mvePIEBALDconsult17-May-08 7:58 
GeneralRe: XML encoding issue Pin
George_George17-May-08 21:33
George_George17-May-08 21:33 
GeneralRe: XML encoding issue Pin
PIEBALDconsult18-May-08 4:48
mvePIEBALDconsult18-May-08 4:48 
GeneralRe: XML encoding issue Pin
George_George20-May-08 3:51
George_George20-May-08 3:51 
GeneralRe: XML encoding issue Pin
PIEBALDconsult20-May-08 14:16
mvePIEBALDconsult20-May-08 14:16 
GeneralRe: XML encoding issue Pin
George_George20-May-08 22:53
George_George20-May-08 22:53 
QuestionSend Object By Value? Pin
Harvey Saayman16-May-08 0:08
Harvey Saayman16-May-08 0:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.