<summary>
Replace partially invalid characters into null
</summary>
XML data returned after <param name= "responsexml" >GTA server response </param>
<returns>string</returns>
private string Converthex (String responsexml)
{
UTF8Encoding encoding = new UTF8Encoding ();
byte[] Responsebytearr = encoding. GetBytes (Responsexml);
for (int i = 0; i < responsebytearr.length; i++)
{
if (Responsebytearr[i] < 32)
{
Responsebytearr[i] = 32;
}
}
return encoding. GetString (Responsebytearr);
}
=======================================
Convertxml is primarily used for XML names and the use of the conversion phase magnetic type with XSD
The following is from MSDN
Encodes and decodes XML names and provides methods for converting between common language type library types and XML Schema definition language (XSD) types. When you convert a data type, the value returned is independent of the locale setting.
The element and attribute names or ID values are limited to a series of XML characters, as recommended by the Extensible Markup Language (XML) 1.0 (second Edition) located in Www.w3.org/TR/2000/REC-xml-20001006.html. When names contain invalid characters, theencodename and decodename methods are used to convert them to valid XML names.
Many languages and applications, such as Microsoft SQL Server and Microsoft Word, allow Unicode characters to be used in their names, which are not valid in XML names. For example, if order Detail is a column header in a database, the database allows spaces between the word order and the Detail. However, in XML, the space between the order and the Detail is treated as an invalid XML character. In this way, the space (an invalid character) needs to be converted to an escaped hexadecimal encoding, and the encoding can be decoded later.
You can use the encodename method and XmlWriter class to make sure that the name you are writing is a valid XML name. The following C # code converts the name "Order Detail" to a valid XML name and writes the element <order_0x0020_detail>my order</order_0x0020_detail>.
|
Copy Code |
Writer. WriteElementString (Xmlconvert.encodename ("Order Detail"), "the", "my"; |
XmlConvert also provides methods that enable you to convert between strings and. NET Framework data types. Zone settings are not considered during data conversion. The data type is based on an XML schema (XSD) data type.