Re: XSL transformation on XML data in SQL 2005 causes 'invalid character' error



Hello

Change the XML stream into unicode string BEFORE feed the data to DB.

param.value=xmltextreader.readouterxml();

I hope I understand your question properly.

"Emil" <e.zegers@xxxxxxxxxx> wrote in message
news:1164039937.681642.3670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Using the code from "Performing XSLT Transforms on XML Data Stored in
SQL Server 2005" [1] I get an 'Invalid character in the given encoding'
error [2].

This error happens when there is a charcater like '? in the XML.
Without 'strange' characters everything works fine.

I suppose this has something to do with the fact that XML data is
stored in UTF-16 in SQL XML data column and original XML data comes in
UTF-8 format but I don't know how to solve this error.

I have changed the encoding for the XmlTextWriter to UTF-8 and Unicode
with no succes.

Hopefully somebody can point me in the right direction.

Regards,

Emil Zegers

[1] http://blogs.msdn.com/mrorke/archive/2005/06/28/433471.aspx

[2]
A .NET Framework error occurred during execution of user defined
routine or aggregate 'ApplyXsltTransform':
System.Xml.XmlException: Invalid character in the given encoding. Line
1, position 9862.
System.Xml.XmlException:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32&
bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32
curPos, Char quoteChar, NodeData attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
at
System.Data.SqlTypes.SqlXml.CreateMemoryStreamFromXmlReader(XmlReader
reader)
at System.Data.SqlTypes.SqlXml..ctor(XmlReader value)
at XSLTTransform.Transform(SqlXml inputDataXML, SqlXml
inputTransformXML)


.



Relevant Pages

  • Re: [ANN] pyxser-1.2r --- Python-Object to XML serialization module
    ... The user may want a different encoding, other than utf-8, it can ... I really meant what I wrote: this is XML. ... serialise the result as a normal Unicode string. ... On the way in, you get a unicode string again, which you can encode to ...
    (comp.lang.python)
  • Re: Want to replace the special char =?UTF-8?B?KOKAoikgd2hpbGUgcg==?= =?UTF-8?B?ICBlYWRpbmcg
    ... when i read xml through xmlreader.read, it gives error on this line. ... An invalid character was found in text content. ... CareerStaff Unlimited, a division of Sun Healthcare Group, ... As Martin suggested, you need to ensure that the character encoding of the document is correct; that is, that the declared encoding matches what the document really is encoded as. ...
    (microsoft.public.dotnet.xml)
  • Re: Want to replace the special char =?UTF-8?B?KOKAoikgd2hpbGUgcg==?= =?UTF-8?B?ZWFkaW5nIHht
    ... Cannot view XML input using XSL style sheet. ... An invalid character was found in text content. ... CareerStaff Unlimited, a division of Sun Healthcare Group, ... You will need to find out how that document is encoded and then you will either need to fix the document to declare its encoding properly or you will need to try to open it with StreamReader where you specify the encoding in the constructor. ...
    (microsoft.public.dotnet.xml)
  • Re: Want Input boxes to accept unicode strings on Standard Window
    ... If ther encoding is not specified, then the encoding is assumed to be ... Ah, UTF-8. ... That would be wrong according to the standard. ... when producing XML files. ...
    (microsoft.public.vc.mfc)
  • Re: tDOM doesnt support encoding=ASCII?
    ... a Tcl channel then Tcl will ... specifically asked for binary encoding), so any XML encoding declaration ... but when tdom sees it it is almost certainly UTF-8. ...
    (comp.lang.tcl)

Loading