When I serialize the XML with tag name including colon, then I get following result after serialization
_x003A_11>
I have following code to generate this XML.
test tc = new test() { str1 = "A1:A#", str2 = "A2", str3 = "A3" };
var serializer = new XmlSerializer(typeof(test));
var memoryStream = new MemoryStream();
var streamWriter = new StreamWriter(memoryStream, System.Text.Encoding.Unicode);
serializer.Serialize(streamWriter,tc);
Byte[] utf8EncodedXml = memoryStream.ToArray();
var stream = new StreamReader(new MemoryStream(utf8EncodedXml));
var cs = stream.ReadToEnd();
[XmlRoot("Test:11")]
public class test
{
public string str1 { get; set; }
public string str2 { get; set; }
public string str3 { get; set; }
}

VulpesPosted Jul 2, 2013, 8:04 AM
However, what you can do is to add another namespace for xsi whose URL can be anything you like as long as it's not the same as Test:
The output now is:
On the second point, you need to introduce another class, tg, and another namespace, tag, as follows:
The output is then:
Ajay PatelPosted Jul 2, 2013, 3:02 AM
This is really good but have minor problem in xml
all thing is good but I want to replace Test with xsi so tag will like
and what to do if child tag have such name means
VulpesPosted Jun 29, 2013, 2:25 PM
This code:
produces the following output:
The URL for the Test namepace can be anything you like.
Ajay PatelPosted Jun 29, 2013, 12:30 AM
It's not necessary that tag name will
VulpesPosted Jun 28, 2013, 6:22 AM
The XML serializer just won't accept it and replaces it with _x003A_ where 3A (decimal 58) is the ASCII hex code for the colon character.
I tried treating Test as a namespace but that didn't work either because "11" is not a valid XML name - it doesn't begin with a letter or an underscore. The serializer just replaces the first "1" with its hex code _x0031_ so that it is now a valid name.
I also tried changing the _x003A_ back to a colon 'manually'. However, when I then attempted to deserialize, I was informed that "Name can't begin with the '1' character".
Ajay PatelPosted Jun 28, 2013, 2:19 AM
VulpesPosted Jun 25, 2013, 7:12 AM
If you don't have to use it, I'd use something harmless such as the underscore instead.