473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

XML parsing error: Invalid unicode character value for this platform

I've seen a couple other posts on this but no real answers. I'm
trying to do a bulk insert and everything is fine until I run the
objCom.ExecuteNonQuery() statement at which point I get the XML
parsing error. Of course, it would be easy to simply wrap unicode
characters with CDATA <![CDATA[ &#xD;&#xA ]]> but is this doable when
passing values to fields to create a row since a whole row is treated
as a single element? I.e.:

<FileProperty File_ID_FK=\"80\" Property_Name_VC=\"Categories\"
Property_Value=\"\" Property_DataType_VC=\"olText\" />\r\n

Is there a way to set encoding to UTF-8? Any wisdom on this would be
greatly appreciated.

(Below is the offending code where I get my error)

Best,

- Rich

************************************************** ****
static void SaveThroughXML(System.Data.DataSet objDS,
System.Data.SqlClient.SqlConnection objCon)
{
DataTable tbl = objDS.Tables["PSTFiles"];
System.Text.StringBuilder sb = new System.Text.StringBuilder( 1000
);
System.IO.StringWriter sw = new System.IO.StringWriter(sb);

foreach( DataColumn col in tbl.Columns)
{
col.ColumnMapping = System.Data.MappingType.Attribute;
}

objDS.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);

SqlCommand objCom = new SqlCommand();
objCom.Connection = objCon;
objCom.CommandType = CommandType.StoredProcedure;
objCom.CommandText = "sp_InsertBlah";

objCom.Parameters.Add( new SqlParameter( "@data",
System.Data.SqlDbType.NText));
objCom.Parameters[0].Value = sb.ToString();;
objCom.ExecuteNonQuery(); // Exception is raised here
}
Nov 12 '05 #1
3 9161
I ran into a similar in a different scenario. I was able to solve it by
passing XmlTextWriter with ASCIIEncoding & passing it to the WriteXml method
of the Dataset object.

Something like ...
*****************
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlTextWriter xmlw = new XmlTextWriter(sw, new ASCIIEncoding());
...
...
objDs.WriteXml(xmlw, System.Data.XmlWriteMode.WriteSchema)
*******************
-Naraen
------------
"RichW" <ri*******@hotmail.com> wrote in message
news:d0*************************@posting.google.co m...
I've seen a couple other posts on this but no real answers. I'm
trying to do a bulk insert and everything is fine until I run the
objCom.ExecuteNonQuery() statement at which point I get the XML
parsing error. Of course, it would be easy to simply wrap unicode
characters with CDATA <![CDATA[ &#xD;&#xA ]]> but is this doable when
passing values to fields to create a row since a whole row is treated
as a single element? I.e.:

<FileProperty File_ID_FK=\"80\" Property_Name_VC=\"Categories\"
Property_Value=\"\" Property_DataType_VC=\"olText\" />\r\n

Is there a way to set encoding to UTF-8? Any wisdom on this would be
greatly appreciated.

(Below is the offending code where I get my error)

Best,

- Rich

************************************************** ****
static void SaveThroughXML(System.Data.DataSet objDS,
System.Data.SqlClient.SqlConnection objCon)
{
DataTable tbl = objDS.Tables["PSTFiles"];
System.Text.StringBuilder sb = new System.Text.StringBuilder( 1000
);
System.IO.StringWriter sw = new System.IO.StringWriter(sb);

foreach( DataColumn col in tbl.Columns)
{
col.ColumnMapping = System.Data.MappingType.Attribute;
}

objDS.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);

SqlCommand objCom = new SqlCommand();
objCom.Connection = objCon;
objCom.CommandType = CommandType.StoredProcedure;
objCom.CommandText = "sp_InsertBlah";

objCom.Parameters.Add( new SqlParameter( "@data",
System.Data.SqlDbType.NText));
objCom.Parameters[0].Value = sb.ToString();;
objCom.ExecuteNonQuery(); // Exception is raised here
}


Nov 12 '05 #2
Naraen -

Thanks so much for your response!

I am trying to implement this and am getting the following errors on the statement:

XmlTextWriter xmlw = new XmlTextWriter(sw, new ASCIIEncoding());

Specifically, on the sw parameter:

Argument '1' cannot convert from 'System.IO.StringWriter' to 'System.IO.Stream'

I get sw from:

StringBuilder sb = new StringBuilder( 1000 );
StringWriter sw = new StringWriter(sb);

Any ideas?

All the best,

- Rich
Nov 12 '05 #3
Rich,
Looks like XmlTextWriter supports the overload for streams but not for
stringwriter.

The best bet would to convert would be to explicitly use the ASCIIEncoding.

E.g.
...
string sUnicodeParm = sb.ToString();
ASCIIEncoding ascii = new ASCIIEncoding();
Byte[] encodedBytes = ascii.GetBytes(unicodeString);
String sAsciiParam = ascii.GetString(encodedBytes);
objCom.Parameters[0].Value = sAsciiParam;
...

-Naraen

------
"RichW" <ri*******@hotmail.com> wrote in message
news:d0*************************@posting.google.co m...
Naraen -

Thanks so much for your response!

I am trying to implement this and am getting the following errors on the statement:
XmlTextWriter xmlw = new XmlTextWriter(sw, new ASCIIEncoding());

Specifically, on the sw parameter:

Argument '1' cannot convert from 'System.IO.StringWriter' to 'System.IO.Stream'
I get sw from:

StringBuilder sb = new StringBuilder( 1000 );
StringWriter sw = new StringWriter(sb);

Any ideas?

All the best,

- Rich

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bekkali Hicham | last post by:
hi, i have already used xalan several times with success, but i have a error message that i don't understand, thanks for your help (Emplacement inconnu de l'erreur) Erreur XSLT...
9
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones...
0
by: Zengfa Gao | last post by:
Hi all, I try to put into some data I backuped. export PGPASSWORD=security cat /opt/myproj/bin/mysave | /usr/bin/psql -h localhost -U myuser DB_Name I got:
1
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
12
by: damjan | last post by:
This may look like a silly question to someone, but the more I try to understand Unicode the more lost I feel. To say that I am not a beginner C++ programmer, only had no need to delve into...
1
by: qbp90x5lb | last post by:
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I...
2
by: ghostrider | last post by:
I've been trying to clear these error messages that I keep getting, was wondering if someone could help me out here. 1. Value of type '1-dimensional array of String' cannot be converted to...
10
by: himanshu.garg | last post by:
Hi, The following std c++ program does not output the unicode character.:- %./a.out en_US.UTF-8 Infinity:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.