I have a stored procedure where I am using sp_xml_preparedocument to handle XML data. But due to some invalid characters like
Ex: 1. INGENIERÍA
2. Engineer'
in XML data, SQL throws an exception as "An invalid character can be found in the text content".
My Stored procedure look like
DECLARE @idoc INT
DECLARE @doc XML
SET @doc = @DocElements -- @Docelements will have XML data
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT BadgeNo FROM OPENXML (@idoc, '/DocumentElement/PEScoreUpdate',2) WITH(BadgeNo VARCHAR(50)))AND
ASRYEAR=YEAR(GETDATE()) And IsPlanDeleted<>1
EXEC sp_xml_removedocument @idoc
Sampel XML data
<DocumentElement>
<PEScoreUpdate>
<Badge_x0020_No>105731</Badge_x0020_No>
<Last_x0020_Name>Vijaya Kumar</Last_x0020_Name>
<First_x0020_Name>Sanjay Kumar</First_x0020_Name>
<BOC>Onshore E&C</BOC>
<Emp_x0020_Class>White Collar</Emp_x0020_Class>
<Site>INGENIERÍA PROJECT Secondment</Site>
</PEScoreUpdate>
</DocumentElement>
I am getting this XML data from an excel sheet with thousands of data so, it's practically not possible to search for invalid text and correct it manually. Anyone guide me how to handle this invalid char in SQL procedure. Is there any way to replace this invalid character but I am processing thousands of data. will it affect performance? Anyone guide me. Thanks in Advance