【问题标题】:XML Parsing: well formed check: undeclared entityXML 解析:格式良好的检查:未声明的实体
【发布时间】:2016-05-17 15:32:10
【问题描述】:

我正在使用 SSMS 2008,但出现以下错误。你知道这是什么意思吗?

Msg 9448, Level 16, State 1, Line 4
XML parsing: line 1, character 89, well formed check: undeclared entity

这是导致此错误的代码:

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

我也用同样的错误结果尝试了这个查询:

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

以下是应用此 XML 语句之前的一些示例数据:

<DIV class=gc-message-sms-row><SPAN class=gc-message-sms-from>TLS: </SPAN><SPAN class=gc-message-sms-text>Hi Reggie... I'm on my way to Lynn.. see you soon</SPAN> <SPAN class=gc-message-sms-time>3:09 PM </SPAN></DIV>
<P>List the intervention targeted from the Intermediary Goal: </P> <P>1. To review on call procedure with family.</P> <P>Interventions attempted during the session to target PCP goal(s):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</P> <P><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">Counselor attempted to call mother; however received an automated message stating this number is temporarily out of service.</SPAN>&nbsp;&nbsp; </P> <P>Effectiveness of Intervention: </P> <P>Not applicable as family was not available for session.</P> <P>Describe safety plan/PCP crisis plan review (reminder - any modification requires new signatures and safety plans need to be reviewed at a minimum monthly)</P> <P>Not applicable as family was not available for session.</P> <P>Therapeutic Homework Assignment (assignment should relate to intervention and be agreed upon by counselor and family):</P> <P>Not applicable as family was not available for session.</P>
This specialist spoke with Kayla in an attempt to schedule a session for this week.&nbsp; Kayla agreed to meet with this specialist on Friday at 10:30am.&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.&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.&nbsp; This specialist stated that this specialist could meet with Kayla prior to that appointment, and then drop Kaya off at the appointment.&nbsp;
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">Purpose of Contact:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">To coordinate with Structured Day Program Director and notify her that faxed has been sent to refer client to program for summer.<B><o:p></o:p></B></SPAN></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"><o:p>&nbsp;</o:p></SPAN></B></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">Description of Contact:<o:p></o:p></SPAN></B></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"><o:p>&nbsp;</o:p></SPAN></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">Counselor spoke with program director to verify she received referral form for client.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>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.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><B><o:p></o:p></B></SPAN></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt"><o:p>&nbsp;</o:p></SPAN></B></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><B><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">Relationship between contact description and treatment goals:<o:p></o:p></SPAN></B></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 9pt">An increase in communication between counselor and director will lead to a collaborative treatment approach and improvement in client's referral behaviors. </SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; FONT-SIZE: 12pt"><o:p></o:p></SPAN></P> <P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P> <P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">Interventions attempted during the session to target PCP goal(s):&nbsp;&nbsp;The counselor met with the&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&nbsp;frames to complete chores are effective. The counselor asked the mother to identify&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&nbsp;within the time frame.<o:p></o:p></SPAN></P> <P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">The counselor and family reviewed personal safety and the court recommendations for the client's protective supervision. The client stated that she is&nbsp;aligned with the&nbsp;following through with the recommendations even while she is on her missions' trip.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></SPAN></P> <P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.<o:p></o:p></SPAN></P> <P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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&nbsp;family and counselor reviewed to client's safety plan. No barriers or breakdowns were identified at this time.&nbsp;<o:p></o:p></SPAN></P> <P style="BACKGROUND: white"><SPAN style="FONT-FAMILY: 'Arial','sans-serif'; FONT-SIZE: 10pt">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.<o:p></o:p></SPAN></P> <P style="MARGIN: 0in 0in 10pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>

我完成了 Ahmed 引用的教程,但我还没有找到如何将 HTML DTD 合并到我的 SQL 代码中。我当然知道这在 HTML 文件中是如何工作的。

因此,我尝试通过 TSQL 将所有出现的“ ”替换为“ ”,但这给了我一个不同的错误:“XML 解析:第 2 行,字符 127,应为字符串文字”。不过,我仍然更喜欢使用 HTML DTD。如何使用上面的 tsql 代码做到这一点?

第 2 行指的是什么?如果它指的是这个示例代码,那么它对我来说没有意义。在替换了上面示例数据中的所有实例后,我查看了与此示例数据的第 2 行相同的第 2 行。而字符 127 = “干预”中的“v”

【问题讨论】:

  • 好的,您需要实际显示您正在解析的 XML;以及 ENTITY DTD 部分;特别是第 1 行字符 85 - 95 无论存在什么实体(可能是 &foo; 之类的东西),它都没有在您的 DTD 中定义......很可能是外部 DTD 问题,但不能确定
  • 你必须原谅我,Ahmed,但我对 XML 真的很陌生。我不明白你在要求什么。我发布的示例数据是 [evolv_cs].[dbo].[progress_note] 表中的 [note_text] 字段。

标签: sql xml


【解决方案1】:

我认为您的 XML 数据中的实体引用 &amp;nbsp; 不正确,因为系统找不到名为 nbsp 的实体。这通常来自 HTML,而不是纯 XML。因此,您必须在 DTD 中使用 HTML DTDs,或者像在 HTML 中一样手动定义该实体,或者在对其进行 XML 处理之前简单地以文本方式过滤数据。

如果你使用 DTD,你可以简单地写进去:

<!ENTITY nbsp "&#160;">

如果不使用它们,只需将所有实体引用 &amp;nbsp; 替换为字符引用 &amp;#160;

【讨论】:

  • 感谢 lkuty,我刚刚更新了我的描述。你能看看吗?我还没有找到如何将您的 DTD 规范合并到我的 tsql 代码中。
  • 事实上,告诉在哪里可以找到 DTD(XML 文档内部和/或外部)的 DOCTYPE 声明应该在 XML 数据中。我不知道你是否有机会这样做。示例数据是否代表您的数据,或者在其顶部是否有一些我们在这里看不到的 XML 声明 &lt;?xml ... ?&gt;?如果不能,更简单的方法是对 XML 数据执行子字符串替换,将任何 &amp;nbsp; 替换为 &amp;#160;。请注意,如果您的 XML 中有许多不同的实体引用,则此方法可能不实用。作为第一次尝试,我会这样做。
  • 这就是我害怕的。不,样本数据是实际数据。我只想删除所有 MS Word 元标记。虽然没有 XML 声明。这就是我所做的——在 nbsp 上替换子字符串,但随后它给了我上面的第二个错误。
  • 好的。请注意,&lt;SPAN class=gc-message-sms-time&gt; 不是 XML,因为属性值 gc-message-sms-time 未包含在 "' 中。我没有检查过,但我猜数据中有很多 XML 格式正确的错误。因此,在考虑使用 XML 之前,您必须对数据进行相当多的处理,否则您必须使用 HTML 解析器解析它们,但我想这不是您想要的。我建议您在 XML 感知编辑器中检查格式正确的错误以枚举不同类型的错误,然后在将其解析为 XML 之前尝试以编程方式处理它们
  • 谢谢lkuty。在这种情况下,我将不得不以不同于 XML 的方式来解决这个问题。不过,我在这个过程中学到了很多关于 XML 的知识。谢谢!
【解决方案2】:

XML 只有五个字符实体引用:&amp;lt; &amp;gt; &amp;apos; &amp;quot; &amp;amp;。您正在使用的 &amp;nbsp; 是一个 HTML(但不是 XML)字符实体引用。不过,您可以写&amp;#160;(十进制)或&amp;#xA0;(十六进制)。

【讨论】:

  • “字符实体引用”不存在。它是“字符引用”或“实体引用”。您可以使用 DTD 定义自己的实体。您提到的五个是内置的通用实体,始终可用。
【解决方案3】:

:-) 不用担心.. 好吧,问题是(如下面的 Ikuty 所指出的)XML 不理解实体...命名实体就像嵌套替换(将它们视为 C 中的 #defines)一个 DTD (文档类型定义)实际上会将诸如 的命名实体映射到目标字符集中的特定字符......这样,如果您更改字符集,您可以更改 DTD 中的实体定义并且您的文档仍然可以。所以.....nbsp 被映射到 UTF-8 中的不间断空格字符 #160 ...这里有一个很好的关于这个主题的入门:Making NBSP work with XML ...您可以逐步找到XML TutorialW3School。希望这有助于作为一个起点:-)

【讨论】:

  • 请注意,在“让   在 XML、RSS 和 Atom 中工作”一文中,使用“实体”一词来标识 &amp;#160; 插入的东西是错误的。 &amp;#160; 是字符引用,因此包含字符集中的字符。它不是实体引用,因此它不会“指向”实体。
  • @Ahmed:我刚刚更新了我的描述。你能看看吗?如何在我的 tsql 代码中使用 lkuty 的 DTD 规范?
猜你喜欢
  • 2016-11-10
  • 2010-11-10
  • 2010-10-06
  • 2013-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
相关资源
最近更新 更多