You must Sign In to post a response.
  • Category: SQL Server

    XML parsing: line 6, character 2, whitespace expected

    DECLARE @x XML = '<table WIDTH="100%" CELLPADDING="1" CELLSPACING="1">
    <tr style="COLOR:black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2;">

    <td><b>Medical Record No. : </b>1165677</td><td><b>Patient Name : </b>MASTER. SURYANARAYANAN T S </td><td><b>Age : </b>16 Year(s)</td><td><b>Sex : </b>male
    </td></tr></table>

    <A HREF="#" TARGET="_top" onContextMenu="event.returnValue=false;

    "onclick ="window.parent.document.getElementById("Base_pgContentHolder_pgContent_hdnScrnId").value="EMRFIRST";
    window.parent.document.getElementById("imgOpenHistory").click();return false;">

    <b>Main Complaints</b></a>
    </table>'

    SELECT t.c.value('.', 'NVARCHAR(MAX)')
    FROM @x.nodes('*') t(c)

    when i run the above shows error as follows

    XML parsing: line 6, character 2, whitespace expected

    line 6 as follows

    "onclick ="window.parent.document.getElementById("Base_pgContentHolder_pgContent_hdnScrnId").value="EMRFIRST";
    window.parent.document.getElementById("imgOpenHistory").click();return false;">
  • #769532
    Hi Rao,

    In your HTML code starts with <A> but ends with </a>. Both start & end tag should match.

    Also, you have written double quote in your onclick parameter. SQL consider this as an XML. In xml the attribute value should not have any other double quotes. That's why you are getting such kind of error.

    I have replaced the double quotes with " in your code and it works fine. Refer the below code,

    DECLARE @x XML = '<table WIDTH="100%" CELLPADDING="1" CELLSPACING="1">
    <tr style="COLOR:black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2;">
    <td><b>Medical Record No. : </b>1165677</td>
    <td><b>Patient Name : </b>MASTER. SURYANARAYANAN T S </td>
    <td><b>Age : </b>16 Year(s)</td>
    <td><b>Sex : </b>male</td>
    </tr>
    </table>
    <a HREF="#" TARGET="_top" onContextMenu="event.returnValue=false; " onclick="window.parent.document.getElementById("Base_pgContentHolder_pgContent_hdnScrnId").value="EMRFIRST" window.parent.document.getElementById("imgOpenHistory").click();return false;"><b>Main Complaints</b></a>'

    SELECT t.c.value('.', 'NVARCHAR(MAX)')
    FROM @x.nodes('*') t(c)

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."


  • Sign In to post your comments