title: XML Parsing: well formed check: undeclared entity
body: <p>I am using SSMS 2008 and I am getting the following error.  Do you know what this means?</p>
  
  <pre><code>Msg 9448, Level 16, State 1, Line 4
  XML parsing: line 1, character 89, well formed check: undeclared entity
  </code></pre>
  
  <p>Here was the code which caused this error:</p>
  
  <pre><code>DECLARE @t TABLE (j VARCHAR(MAX))
  insert into @t
  SELECT 
  z.MyXml.value('.','NVARCHAR(MAX)') value
  FROM  [evolv_cs].[dbo].[progress_note] 
  CROSS APPLY (SELECT CAST([progress_note].[note_text] AS XML) [MyXml]) z
  </code></pre>
  
  <p>I also tried this query with same error results:</p>
  
  <pre><code>SELECT 
  z.MyXml.value('.','NVARCHAR(MAX)') value
  INTO #TEMP_PN
  FROM  [evolv_cs].[dbo].[progress_note] 
  CROSS APPLY (SELECT CAST([progress_note].[note_text] AS XML) [MyXml]) z
  </code></pre>
  
  <p>Here is some sample data before applying this XML statement: </p>
  
  <pre><code>&lt;DIV class=gc-message-sms-row&gt;&lt;SPAN class=gc-message-sms-from&gt;TLS: &lt;/SPAN&gt;&lt;SPAN class=gc-message-sms-text&gt;Hi Reggie... I'm on my way to Lynn.. see you soon&lt;/SPAN&gt; &lt;SPAN class=gc-message-sms-time&gt;3:09 PM &lt;/SPAN&gt;&lt;/DIV&gt;
  &lt;P&gt;List the intervention targeted from the Intermediary Goal: &lt;/P&gt; &lt;P&gt;1. To review on call procedure with family.&lt;/P&gt; &lt;P&gt;Interventions attempted during the session to target PCP goal(s):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt; &lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 9pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Counselor attempted to call mother; however received an automated message stating this number is temporarily out of service.&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt; &lt;P&gt;Effectiveness of Intervention: &lt;/P&gt; &lt;P&gt;Not applicable as family was not available for session.&lt;/P&gt; &lt;P&gt;Describe safety plan/PCP crisis plan review (reminder - any modification requires new signatures and safety plans need to be reviewed at a minimum monthly)&lt;/P&gt; &lt;P&gt;Not applicable as family was not available for session.&lt;/P&gt; &lt;P&gt;Therapeutic Homework Assignment (assignment should relate to intervention and be agreed upon by counselor and family):&lt;/P&gt; &lt;P&gt;Not applicable as family was not available for session.&lt;/P&gt;
  This specialist spoke with Kayla in an attempt to schedule a session for this week.&amp;nbsp; Kayla agreed to meet with this specialist on Friday at 10:30am.&amp;nbsp; This specialist asked Kayla about the upcoming meeting with DCF and Kayla stated that it is about her coming transition, but did not want to discuss it further.&amp;nbsp; Kayla asked if this specialist would meet with her on Monday as well, to take her downtown to go to a meeting at a modeling agency.&amp;nbsp; This specialist stated that this specialist could meet with Kayla prior to that appointment, and then drop Kaya off at the appointment.&amp;nbsp;
  &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;Purpose of Contact:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;To coordinate with Structured Day Program Director and notify her that faxed has been sent to refer client to program for summer.&lt;B&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;Description of Contact:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;Counselor spoke with program director to verify she received referral form for client.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Director confirmed that she received clients referral form but reported that due to the waiting list being so long that client would more than likely not be able to attend program for the summer, but would keep client on waiting list and notify counselor if a slot becomes available.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;Relationship between contact description and treatment goals:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"&gt;An increase in communication between counselor and director will lead to a collaborative treatment approach and improvement in client's referral behaviors. &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman','serif'; FONT-SIZE: 12pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
  &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;List the intervention targeted from the Intermediary Goal: The mother will assess what is working well in her home to assist the client with decreasing her referral behaviors.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Interventions attempted during the session to target PCP goal(s):&amp;nbsp;&amp;nbsp;The counselor met with the&amp;nbsp;mother and the client in the home for a face to face session. The counselor noted that the client and the mother were working together to complete household chores. The counselor asked the family to assess if the time frames to complete the chores id effective for the family. The mother and the client reported that the time&amp;nbsp;frames to complete chores are effective. The counselor asked the mother to identify&amp;nbsp;what is effective to assist the client with maintaining her decreased negative behaviors. The mother reported that by educating the client on her expectations and allowing her to make the choice to comply is effective. The counselor and family role played communicating the expectations. The counselor noted that the mother will give the client a directive and allow her a time frame to complete the directive. The client stated that now that her mother leaves her alone once she tells her what to do allow her time to process what her mother wants her to do. The client reported that she does not get upset anymore because she can complete the task&amp;nbsp;within the time frame.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;The counselor and family reviewed personal safety and the court recommendations for the client's protective supervision. The client stated that she is&amp;nbsp;aligned with the&amp;nbsp;following through with the recommendations even while she is on her missions' trip.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Effectiveness of Intervention: The intervention appeared to be effective as evidenced by the family's willingness to identify barriers that may prevent them from follow through with identified contingences in the home.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Describe safety plan/PCP crisis plan review (reminder - any modification requires new signatures and safety plans need to be reviewed at a minimum monthly) The&amp;nbsp;family and counselor reviewed to client's safety plan. No barriers or breakdowns were identified at this time.&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="BACKGROUND: white"&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt"&gt;Therapeutic Homework Assignment (assignment should relate to intervention and be agreed upon by counselor and family): The mother was asked to review the safety plan with identified supports. The client as asked to follow through with obtaining contact numbers for her new peers from church.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt; &lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
  </code></pre>
  
  <p>I finished going through the tutorials Ahmed referenced, but I didn't yet find how to incorporate the HTML DTD into my SQL code.  I see how this might work in an HTML file of course.  </p>
  
  <p>So instead I tried replacing all "&nbsp;" occurrences with "&#160;" via TSQL, but this gave me a different error: "XML parsing: line 2, character 127, A string literal was expected".  I would still prefer to use the HTML DTD however.  How do I do that with the tsql code above?</p>
  
  <p>What is line 2 referring to?  If it is referring to this sample code then it does not make sense to me.  After replacing all &nbsp; instances in the sample data above, I looked at line 2 which is the same as line 2 of this sample data.  And character 127 = "v" from "interventions"</p>