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
}
0
richbward (3)
4/1/2004 9:51:22 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
392 Views

Similar Articles

[PageSpeed] 0

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" <richbward@hotmail.com> wrote in message
news:d0eab59.0404011351.37398706@posting.google.com...
> 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
> }



0
naraen (10)
4/2/2004 7:27:00 AM
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
0
richbward (3)
4/6/2004 8:54:46 PM
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" <richbward@hotmail.com> wrote in message
news:d0eab59.0404061254.36c1069f@posting.google.com...
> 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


0
naraendira (21)
4/9/2004 5:19:04 AM
Reply:

Similar Artilces:

Syntax error (missing operator) 04-06-10
Hi, I used the following code supplied by Rick Brandt to a message from a 2005 post "Open Forms in Hidden Mode" where user was using one form to open another form to extract data. Dim db as Database Dim rs as Recordset Dim strSQL as String strSQL = "SELECT FieldName " & _ "FROM TableName " & _ "WHERE SomeField = SomeValue" Set db = CurrentDB Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot) If rs.EOF = True Then 'No matching records found (do whatever) Else 'In here values can be extracted by... SomeVariable = rs!Fi...

XML that one of its elements has line break.
Hello, I am using access as my database, One of my columns is memo field, so it has sevral line at its context. Can I convert line break to something readable in XML ? Is there any function for that ? Thanks :) Same thing. Any character, be it ascii or unicode has it's place or number. If Access bitches, it is Access and not Calculus. "Mr. x" <a@b.com> wrote in message news:uaYLyYxeDHA.4024@TK2MSFTNGP11.phx.gbl... > Hello, > I am using access as my database, > One of my columns is memo field, so it has sevral line at its context. > Can I convert line b...

Help on subscript out of range error (VB6/VBA)
Hi, I want to work with multiple excel workbooks en worksheets using a stand alone VB6 application. 1. First I open and close the workbooks and populate a listbox with sheetnames. 2. Then I select some sheets and fill an Array. (This array contains sheetnames from different workbooks) 3. The last step is to open and close the workbooks again and loop (For Each) through the sheets to get the information I need using the above mentioned array. The only problem is that I receive an "Subscript out of Range" error. This error occurs because I'm attempting tot access a workshee...

HELP! **Transfer orders to invoices error
I need some serious help. We just upgraded from GP 7.5 to GP 8.0 and now I am unable to transfer orders to invoices. I keep getting an error that says "Order ORD1555 has no line items to transfer to Invoice INV144408." Order# 1555 does have about 10 line items, which I can view on the screen. I did go in and run the "Check Links" function, but it hasn't done anything. This is our busiest time of year and a really bad time for something like this to happen. Can someone please give me some advice on how to fix this? if this is just one order, why not cancel...

MSExchangeIS Public Store Errors 1110
We are running Exchange Verson 6.0 (Build 6249.4; Service Pack 3 We are getting the following error 39 times every hour Event Type: Erro Event Source: MSExchangeIS Public Stor Event Category: General Event ID: 111 Date: 2/20/200 Time: 6:21:36 P User: N/ Computer: MAI Description Error 0x0 occurred while writing per-user information for <user@outdomain.com> on database "Staff\Public Folder Store (MAIL)". For more information, click http://www.microsoft.com/contentredirect.asp. This error is supposed to be solved by the service pack (Q312966). We applied...

We are getting stat=Deferred: Connection reset errors .....
Does anyone know how to fix this issue? I am getting a lot of emails BUT an Exchange admin from another company that sends SMTP email to is saying that he sees a lot of stat=Deferred: Connection reset error messages in his log file. very very weird. Has anyone seen this issue? He can telnet to the server fine etc... plus I am getting email from his company but it is deferring aa ton though. Thanks What version of Exchange and SP level Oliver Exchange 5.5 SP 4 is our IMS. "Oliver Moazzezi" wrote: > What version of Exchange and SP level > > Oliver > >...

Object or class does not support the set of events Error
This post is for anyone who has seen this problem. I have posted a solution below. Situation: The error message "Object or class does not support the set of events" occurred in my database just after I received a "database corruption error". The corruption error appeared right after I closed then reopened my database. I assumed this happened because I opened it immediately after it crashed and I had recently set the database to auto compact & repair on close. MS Access asked me if I wanted to save a backup, and I said yes. After this, neither the original database...

Where can we get xml scheme for tuning setting of WM2003/WM5.0 PDA
Hi all, We are working upon setting up a lot of WM2003/WM5.0 empowered mobile devices according with company standards. As far as I know these settings are tuned through xml file. Then this xml file has to be deployed deployed/executed onto mobile device. My question is where xml scheme for tuning such setting is published so we may assign necessary properties referencing it? Thank you in advance. ...

Another oddball WLM error message
When I left WLM running while I went to breakfast this morning, I got another oddball error message. Just the frame for showing the error message, with all the space inside the frame still transparent. Robert Miles ...

is there a way to check flowcharts for programming errors?
I am in an intro to programming class and have no experience with programming. Does the Visio program offer a way to double check your flowchart for programming errors? I am a terrible perfectionist and don't like to turn something in until I have double checked it first. Thanks! Visio does not check interpret the flow chart thus you should implement the flow chart in some programming language and check the results. Deepa -- http://www.EventHelix.com/EventStudio EventStudio 2.5 - Generate Sequence diagrams from a simple declarative language ...

Error created when try to Print Preview or Print
When try to print or print preview system is generating an error: "Print titles must be contiguous and complete rows or columns." Used excel for years ever seen this error before. Using Excel 2007 on Vista, we just upgraded to SP2 for both systems. After testing a few times, I notice that system is generating a Name Range with no referencing cell range, the name range is called Print_Titles. If I delete the name range it removes the error message and able to use print preview and able to print. Notice it is occurring more ofter when client is copying a worksheet to ...

ERROR 20488
I am using GP 7.0. I am helping to set up a new additional company. And I have posted many entries from Sub-ledger model to G/L model, and they worked fine. However, last Friday, when I post from Bank transaction model to G/L model, the system shows: DBMS 0, Great Plains 20488. I searched that in the knowledge base, they said that it might be the Posting Definitions Master talbe is damaged. But the above solution applies to GP 8.0, I only use GP7.0, and my posting is OK before. Can anyone help me on that? Thanks, Gavin ...

how to produce a csv file from a unicode-saved text file
Friends, I have an excel spreadsheet (version 2000) that has Japanese characters. I would like to save it as unicode text file so that I can FTP it to my unix box for loading into an Oracle database. When I save the file as unicode text, it properly preserves the characters, but using whitespace as the delimiters. I would like to change this to a csv, but when I save as the file as CSV, the Japanese characters turn into set of ?? symbols. Is there any way around to create the unicode text file with delimiters other than whitespace? Thanks for any ideas. - Sal ...

Flag a value in a group...
Hi all, tia for any insight. I have the following query that gives some totals for qty's in a releases table, pulling and grouping information (part number, rev and desc) from a details table. Table heirarchy is (one to manys) tblOrders -> tblOrderDetails -> tblOrderReleases SELECT tblOrderDetails.fldPart, tblOrderDetails.fldRev, tblOrderDetails.fldDescription, Min(tblOrderReleases.fldDueDate) AS cfldFirstDue, Sum([tblOrderReleases].[fldQty])-Sum([tblOrderReleases].[fldQtyToBE]) AS cfldQtyToProcess FROM tblOrders LEFT JOIN (tblOrderDetails LE...

Error 9316
Hi, I've been seeing error 9316 in my logs. Looked it up in technet and found article Q247782 which recomended I set the XAPI concurent connections to 50. It was already set at 50 and I can find no further info. Before I do the obvious hit in the dark I though I'd ask if anyone else has had the same experience? TIA, Pete ...

Excel macro error msg..
Hi I get the following msgbox when I attempt to run a Macro - which is just a simple text string to be put into a cell. " 'xxx'.xls could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open a file from your list of most recently used files on the file menu, make sure that the file has not been renamed , moved or deleted." (ok) 'xxx.xls' trefers to a file name that was on my disk - but I deleted - I can't find it after a search. All macros when run, exhibit the same thing..... Tried a goog...

Outlook IMAP Error
I'm getting the following intermittent error when Outlook tries to receive mail from an IMAP server: Task 'Checking for new mail in subscribed folders on <email address>.' reported error (0x8004DF0B) : 'Outlook is unable to download folder (null) from the IMAP e-mail server for account <email address>. Error: The connection to the server is unavailable. Outlook must be online or connected to complete this action. If you continue to receive this message, contact your server administrator or Internet service provider (ISP).' We are on a wired LAN, and ...

451 Internal error
Hi, I would appreciate any help on this problem. When trying to send a single 5 meg file through my web smtp server (Go Daddy) I get a return error message stating; "your outgoing (smtp) e-mail server has reported an internal error".. "The server responded: 451 Internal error" Note: I can send a 3 meg file with no problems and can receive a 5 meg file. Go Daddy tech support person said "it appears the error you are receiving is due to a program running on the server with is aimed at blocking viruses being sent out, and the server also runs anti-phishing software. T...

Outlook 2003
Getting "The messaging interface has returned an unknown error. If problem persits, restart Outlook." when attempting to forward, send or reply, using Outlook 2003. Restarting does not help. If you delete the NT Profile the problem goes away for a few days and then returns. We have also tried "Detect and repair" and Uninstall / re-install without good results. Only replacing the NT Profile seems to have an impact. Help! ...

Correcting errors
Is there any way to change the tender type that a Cashier has entered if they do it wrong? Someone settles the credit card as AMEX when it's really a Visa and I want the Z report to be correct. Any ideas? If you still have the card available, void the sale then re-enter it. If you don't have the card, it's really not worth the trouble or the risk... To prevent this from happening again, setup Validation masks for each credit card tender type. Amex: 3############## MC 5############### Visa 4############### Discover 6############### Glenn Adams Tiber Creek Consulting http://...

error when opening large file
Hi, I am trying to open a large file in Publisher 2002, and Publisher just closes right up. ANy clues? How large is large? Do you get any error message? Did you create this file or was it passed on to you? -- JoAnn Paules - MVP Microsoft Publisher "sherri" <anonymous@discussions.microsoft.com> wrote in message news:1d10701c4229e$127b63b0$a101280a@phx.gbl... > Hi, I am trying to open a large file in Publisher 2002, > and Publisher just closes right up. > > ANy clues? Have you got the garbage trash junk Symantec Norton installed? If you have, RE-move/UN-i...

How Do I specify where XML data gets imported into Excel
I have XML data that I would like to import up as fllows in a spreasheet: Cell A2: Job Number Cell A3: Customer Number A4 through A29 should recive the <AMOUNT> data B4 through B29 should receive the <QUANTITY> data etc etc Sometimes all the fields will be filled, sometimes not. Any help would be greatly appreciated. Regards, Diane Hi Diane! You should see therre: microsoft.public.xml Starwing ...

Blue Screen
Machine says a problem has occured and has shut windows down to prevent damage to computer. followed by page_fault_in_Nonpaged_area? I have not installed any new hardware or software. Stop: (0x00000050, 0x80098004, 0x0000001, 0x80515103,0x00000000). I have tried starting in safe mode, normal mode, last known good config.. and I still get this blue screen... I tested all my drivers and system and still NO LUCK I even tried re-installing WindowsXP cd... Not sure of next step other than to take it to the tech store.... Any and all help is greatly appreciated... =?Utf-8?B?SG9vcG...

Set a default value to Drop Down Box
Is it possible to set a 'default' value to a drop down box, so that n matter what value was selected when it was saved, when the workboo opens it changes to the default value? I have a written a macro to do this for all the input cells that ar not drop downs, but cannot figure out a way to change values in dro down forms. Thanks Bria -- Message posted from http://www.ExcelForum.com What's the default value? The first on the list? If yes: Option Explicit Sub auto_open() Dim wks As Worksheet Dim myDD As DropDown For Each wks In ThisWorkbook.Worksheets ...

log parsing question
Is there any tool or script that allows one to parse the SMTP logs for servers connecting to bad addresses then given X number of bad addresses, add them to a block list? I have seen an uptick in servers connecting with automated attempts at email addresses which do not exist and never have, and I know it is an obvious spam attempt. I'd like to auto block them after a few junk attempts that don't match addresses in the AD. Any ideas? Is it worth the effort? thanks "tester" <tester@testthis.net> wrote in news:11cntk5jgnedpe6@corp.supernews.com: > Is there...