Thanks Shuhai, I could create the XML with UTF-8 but when I did a transform with the stylesheet as in my previous thead to indent it, the encoding changed to UTF-16. I found another approach to to do. I renamed the attribute from UTF-8 to UTF-16 MSXML::IXMLDOMNodePtr pXMLFirstChild = pXMLFormattedDoc-GetfirstChild; // MSXML::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild-Getattributes; // A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair MSXML::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap-getNamedItem(T('encoding')); pXMLEncodNode-PutnodeValue(T('UTF-8')). Thanks Shuhai, I could create the XML with UTF-8 but when I did a transform with the stylesheet as in my previous thead to indent it, the encoding changed to UTF-16. I found another approach to to do. I renamed the attribute from UTF-8 to UTF-16 MSXML::IXMLDOMNodePtr pXMLFirstChild = pXMLFormattedDoc-GetfirstChild; // MSXML::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild-Getattributes; // A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair MSXML::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap-getNamedItem(T('encoding')); pXMLEncodNode-PutnodeValue(T('UTF-8')). Usually UTF-8 is the default encoding, unless you transform to a string which is UTF-16 encoded.
So make sure you use transformNodeToObject and not transformNode, then you should not need to fix the encoding. MVP XML I used TransformNodeToObject only.
Following is my style sheet. Still the resulting XML encoding is UTF-16.
String xmlDoc = stringXmlDoc.Replace(“?xml version= '1.0 ' encoding= 'UTF-8 '?>“, “”); If we are writing an xml document and don’t want to write xml declaration in the xml doc then use the ConformanceLevel and OmitXmlDeclaration properties.
I am updating an xml column in SQLServer 2005, but it always gives me an error 'XML parsing: line 1, character 38, unable to switch the encoding' my csharp is like the following cmd.Parameters.Add('@xml', SqlDbType.Xml); cmd.Parameters'@xml'.Value =xmldata; My xml have the following line '.' If I remove this line, everything is OK, looks like the SQLParameter is set to UTF-16 and my xml data is set to UTF-8, how do I make SQLParameter take UTF-8? I did not see any properties under SQLParameter to change the encode. Please advice. Thanks in advance.
Well I do search a bit and perhaps you want to remove that line before you insert it in to the column. Chanmm 'John' wrote in message news:[email protected] ups.com. I am updating an xml column in SQLServer 2005, but it always gives me an error 'XML parsing: line 1, character 38, unable to switch the encoding' my csharp is like the following cmd.Parameters.Add('@xml', SqlDbType.Xml); cmd.Parameters'@xml'.Value =xmldata; My xml have the following line '.'
If I remove this line, everything is OK, looks like the SQLParameter is set to UTF-16 and my xml data is set to UTF-8, how do I make SQLParameter take UTF-8? I did not see any properties under SQLParameter to change the encode. Please advice. Thanks in advance. Try using SqlDbType.VarChar (even if your parameter in the proc is really XML). This worked for me. Reason is likely that you're using a System.String (Unicode) and the XML data type is internally UTF-16, so telling it UTF-8 is switching encodings, after its 'decided' you wanted UTF-16.
There is automatic string conversion if the encoding matches the SQL varchar data type. Bear in mind, you'll always get the data out as UTF-16. Cheers, Bob Beauchemin 'John' wrote in message news:[email protected] ups.com. I am updating an xml column in SQLServer 2005, but it always gives me an error 'XML parsing: line 1, character 38, unable to switch the encoding' my csharp is like the following cmd.Parameters.Add('@xml', SqlDbType.Xml); cmd.Parameters'@xml'.Value =xmldata; My xml have the following line '.' If I remove this line, everything is OK, looks like the SQLParameter is set to UTF-16 and my xml data is set to UTF-8, how do I make SQLParameter take UTF-8? I did not see any properties under SQLParameter to change the encode.