Microsoft KB Archive/914159

= Error message when you try to browse a report in SQL Server 2005 Reporting Services: &quot;The input XML is not well-formed&quot; =

Article ID: 914159

Article Last Modified on 2/27/2006

-

APPLIES TO


 * Microsoft SQL Server 2005 Reporting Services

-





SYMPTOMS
When you try to browse a report in Microsoft SQL Server 2005 Reporting Services, you may receive an error message that is similar to the following:

The input XML is not well-formed. One or more elements is missing a closing tag or has mismatched tags. (rsMalformedXml)

, hexadecimal value, is an invalid character. Line 20, position 18.

Note In this error message,  is a placeholder for a nonprintable character. Additionally,  is a placeholder for the character code of the nonprintable character.



CAUSE
This problem occurs because a nonprintable character is populated into a report parameter that you define in the report.



WORKAROUND
To work around this problem, use one of the following methods:
 * Remove the nonprintable character from the available values for the report parameter.
 * Convert the nonprintable character to the printable character in the available values for the report parameter. Then, convert the printable character back to the nonprintable character in the values for the query parameter.

Example workaround
The following example shows how to work around this problem. In this example, the following assumptions are made:
 * The DEP report parameter is defined and is populated with nonprintable characters.
 * The FirstName column contains nonprintable characters. The FirstName column is in both the Dataset1 dataset and the Dataset2 dataset.
 * The available value for the DEP report parameter is from a query on the Dataset1 dataset.
 * The value for the DEP report parameter is passed to the Dataset2 dataset as the @DEP parameter in the query string of the Dataset2 dataset.
 * The range of character codes of the nonprintable characters that you experience is from 2 to 8.
 * The MyEncodingFunc function and the MyDecodingFunc function are defined. The MyEncodingFunc function analyzes the input string. Based on the Strip parameter, the MyEncodingFunc function either converts the nonprintable characters to the <> string or strips the nonprintable characters. The MyDecodingFunc function does the opposite.

Notes
 * A code example for the MyEncodingFunc function and for the MyDecodingFunc function is provided later in this article.
 * is a placeholder for the character code of the nonprintable character.

To work around this problem, follow these steps:  Put the code for the MyEncodingFunc function and for the MyDecodingFunc function in the Custom code box. A code example is provided later in this article. To access the Custom code box, follow these steps:  On the Report menu, click Report Properties. Click the Code tab.  Add a calculated field to the Dataset1 dataset. To do this, follow these steps:  In the Datasets window, right-click the dataset, and then click Add.</li> In the Name box, type a name. In this example, type the name MyCalculatedField .</li> Click Calculated field, and then type = code.MyEncodingFunc(Fields!FirstName.Value,False) .</li> Click OK.</li></ol> </li> Add another calculated field to the Dataset1 dataset. To do this, follow these steps:  In the Datasets window, right-click the dataset, and then click Add.</li> In the Name box, type a name. In this example, type the name MyDisplayField .</li> Click Calculated field, and then type = code.MyEncodingFunc(Fields! .Value,True) .</li> Click OK.</li></ol> </li> On the Report menu, click Report Parameter.</li> In the left pane, click the DEP report parameter.</li> In the right pane, click MyCalculatedField in the value field list, and then click MyDisplayField in the label field list.</li> Click OK.</li> In Report Designer, click the Data tab, and then click Dataset2 in the Dataset list.</li> Click the ellipsis button, and then click the Parameter tab.</li> <li>Define a new query parameter by specifying the name. In this example, type the name MyQParam. For the value of the MyQParam query parameter, type =Code.MyDecodingFunc(Parameters!DEP.Value) .</li> <li>In the query string of the Dataset2 dataset, replace the @DEP parameter with the @MyQParam query parameter.</li></ol>

This example removes the nonprintable characters from the DEP report parameter. The DEP report parameter is displayed as a list. You can still see the nonprintable characters in the report for the FirstName column. To remove the nonprintable characters from the report for the FirstName column, follow these steps:
 * 1) In Report Designer, click the Layout tab.
 * 2) Change the content of the detail row of the FirstName column from =Fields!FirstName.Value to =code.MyEncodingFunc(Fields!FirstName.Value,True).

The following code example is the code for the MyEncodingFunc function and for the MyDecodingFunc function. Public Function MyEncodingFunc(ByVal strIn, ByVal Strip) As String 'The value of the Strip parameter determines whether the nonprintable character is stripped from the input string. Dim n As Integer Dim resStr As String Dim tempStr As String resStr = &quot;&quot; For n = 1 To Strings.Len(strIn) tempStr = Mid(strIn, n, 1) If ((Asc(tempStr) >= 2) And (Asc(tempStr) <= 8)) Then If Strip = False Then resStr = resStr + &quot;<<Char(&quot; + Convert.ToString(Asc(tempStr)) + &quot;)>>&quot; End If           Else resStr = resStr + tempStr End If       Next Return resStr End Function

Public Function MyDecodingFunc(ByVal strIn) As String Dim n As Integer Dim resStr As String Dim tempStr As String resStr = &quot;&quot; For n = 1 To Strings.Len(strIn) If Mid(strIn, n, 7) = &quot;<<Char(&quot; Then               tempStr = &quot;&quot;                n = n + 7                Do Until Mid(strIn, n, 1) = &quot;)&quot; tempStr = tempStr + Mid(strIn, n, 1) n = n + 1 Loop n = n + 2 resStr = resStr + Chr(Convert.ToInt32(tempStr)) Else resStr = resStr + Mid(strIn, n, 1) End If       Next Return resStr End Function

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

Keywords: kbtshoot kbsqlclient kbprb kbexpertiseadvanced kbsql2005rs KB914159

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.