Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

I am Uday Satardekar.
i am inserting 10000 rows using csharp

i am using xml to send bulk data.
but in some situation it throws
white space is not allowed at this location error

i am generating dynamic xml from excel.

But excel contains some special character so
error is created during xml generation how i an solve and replace it
my code in c sharp is

C#
StringBuilder XML_TRANSACTIONDETAILS = new StringBuilder();

XML_TRANSACTIONDETAILS.Append("<master>");
for (int i = 0; i < excelRows; i++)
{
    maxid = maxid + 1;

    XML_TRANSACTIONDETAILS.Append("<TRANSACTION>");
    XML_TRANSACTIONDETAILS.Append("<maxid>" + maxid + "</maxid>");

    for (int j = 0; j < ExcelColumnCount; j++)
    {
         string xmlTag = cleanedEmailTbl.Columns[j].ToString();


         XML_TRANSACTIONDETAILS.Append("<" + xmlTag + ">" + cleanedEmailTbl.Rows[i][j].ToString() + "</" + xmlTag + ">");
    }

    XML_TRANSACTIONDETAILS.Append("</TRANSACTION>");
}

XML_TRANSACTIONDETAILS.Append("</master>");





and error is:

The error description is 'Whitespace is not allowed at this location.'.<br />
Could not find prepared statement with handle 0.<br />
Could not find prepared statement with handle 0.<br />
Could not find prepared statement with handle 0.<br />
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.<br />
The statement has been terminated.<br />
The statement has been terminated.<br />
The statement has been terminated.


Please tell me how to remove

thanks in advance
Posted
Updated 6-Dec-11 18:27pm
v7
Comments
Herman<T>.Instance 18-Aug-11 7:55am    
trim function?

Try to rewrite it in this way and see what happens

C#
for (int j = 0; j < ExcelColumnCount; j++)
{
    string xmlTag = cleanedEmailTbl.Columns[j].ToString().Trim();

    XML_TRANSACTIONDETAILS.AppendFormat("<{0}>{1}</{0}>", xmlTag, cleanedEmailTbl.Rows[i][j]);
}


Let us know.
 
Share this answer
 
v2
I suspect that every once in a while your xmlTag value contains one or more whitespace characters). If yu run it under the debugger, and inspect the variable when it throws the exception, you can verify my assumption.

If your table contains columns with spaces in their names, shame on you. You can change the offending column names in the table as long as you remember to change any related stored procs or in-code sql queries.
 
Share this answer
 
Comments
jitujd007 9-Sep-16 12:25pm    
i encode the html and its now working for me.
Thank you!
Thank you sir .
Its working for me.
 
Share this answer
 
Comments
udusat13 24-Aug-11 0:07am    
yes its working for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900