Click here to Skip to main content
14,326,008 members
Rate this:
Please Sign up or sign in to vote.
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

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
digimanus 18-Aug-11 7:55am
   
trim function?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try to rewrite it in this way and see what happens

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.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Comments
jitujd007 9-Sep-16 12:25pm
   
i encode the html and its now working for me.
Thank you!
Rate this:
Please Sign up or sign in to vote.

Solution 3

Thank you sir .
Its working for me.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100