narasiman rao

narasiman rao

  • NA
  • 519
  • 768.4k

XML parsing: line 14, character 49, whitespace expected

Dec 11 2017 11:59 AM
DECLARE @x XML = '<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2"><td>
<b>Medical Record No. : </b>1000011 </td><td><b>Patient Name : </b>MR. ANANTHA NARAYANAN S </td>
<td><b>Age : </b>60 Year(s)</td><td><b>Sex : </b>male</td></tr></table>
<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2">
<td><b>Address : </b>SWASTHIK, B21 BEACH 2ND STREET, AGS COLONY, KOTTIVAKKAM, CHENNAI,</td></tr>
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2">
<td>TAMIL NADU, INDIA - 600 041.</td>
</tr>
</table>'
SELECT t.c.value('.', 'NVARCHAR(MAX)')
FROM @x.nodes('*') t(c)
 
when i run the above query output i get correctly as follows
 
Medical Record No. : 1000011 Patient Name : MR. ANANTHA NARAYANAN S Age : 60 Year(s)Sex : male
Address : SWASTHIK, B21 BEACH 2ND STREET, AGS COLONY, KOTTIVAKKAM, CHENNAI,TAMIL NADU, INDIA - 600 041.
 
But when i execute the below query
 
DECLARE @x XML = '<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2"><td>
<b>Medical Record No. : </b>1000011 </td><td><b>Patient Name : </b>MR. ANANTHA NARAYANAN S </td>
<td><b>Age : </b>60 Year(s)</td><td><b>Sex : </b>male</td></tr></table>
<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2">
<td><b>Address : </b>SWASTHIK, B21 BEACH 2ND STREET, AGS COLONY, KOTTIVAKKAM, CHENNAI,</td></tr>
<tr style="COLOR: black; FONT-FAMILY: Arial;FONT-SIZE: 10pt; BACKGROUND-COLOR: #f2f2f2">
<td>TAMIL NADU, INDIA - 600 041.</td>
</tr>
<A HREF="#" TARGET="_top" onContextMenu="event.returnValue=false;"
onclick="window.parent.document.getElementById("Base_pgContentHolder_pgContent_hdnScrnId").value="opnion-Glass";
</table>'
SELECT t.c.value('.', 'NVARCHAR(MAX)')
FROM @x.nodes('*') t(c)
 
Error as follows
 
XML parsing: line 14, character 49, whitespace expected
My string value is HTML code, it is not XML. how to overcome the above error.
 
But i want output as follows
Medical Record No. : 1000011 Patient Name : MR. ANANTHA NARAYANAN S Age : 60 Year(s)Sex : male
Address : SWASTHIK, B21 BEACH 2ND STREET, AGS COLONY, KOTTIVAKKAM, CHENNAI,TAMIL NADU, INDIA - 600 041.
opnion-Glass

Answers (1)