You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL Server XML转换报错:XML解析第3行第119位缺少等号,求解决

Fixing XML Parsing Error: "equal expected" When Converting HTML String to XML in SQL

Hey there, let's break down why your XML conversion is throwing that error and how to fix it quickly.

The Root Cause

SQL's convert(XML, ...) function enforces strict well-formed XML rules, and your HTML string has invalid syntax for XML: unquoted, value-less attributes. In HTML, you can write attributes like DISABLED or REQUIRED without assigning a value, but XML requires every attribute to have a name-value pair (e.g., DISABLED="DISABLED" or DISABLED="").

Looking at your input string, the problematic parts are:

  • <input ... DISABLED> (line 3, around character 119)
  • <textarea ... DISABLED REQUIRED>

XML parsers see these and throw the "equal expected" error because they're expecting an = sign followed by a quoted value after the attribute name.

The Fix

Update your input string to convert those value-less attributes into XML-compliant form. The most common approach is to set the attribute value to match its name (e.g., DISABLED="DISABLED"), though you can also use an empty string if preferred.

Here's the corrected SQL code:

Create table #temp ( NAME VARCHAR(MAX) )
Insert Into #temp select '&lt;div class=&quot;form-group form-row&quot;&gt;&lt;label class=&quot;col-sm-5 control-label&quot;&gt;Account Name&lt;/label&gt;&lt;div class=&quot;form-controls&quot;&gt;&lt;div class=&quot;form-control-static&quot;&gt;Bond&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;form-group form-row&quot;&gt;&lt;label class=&quot;col-sm-5 control-label&quot;&gt;Account Number&lt;/label&gt;&lt;div class=&quot;form-controls&quot;&gt;&lt;div class=&quot;form-control-static&quot;&gt;PQR&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;form-group&quot;&gt; &lt;label class=&quot;control-label&quot;&gt;Specific subject&lt;/label&gt; &lt;input class=&quot;input-text form-control&quot; type=&quot;text&quot; name=&quot;Specific subject&quot; size=&quot;20&quot; value=&quot;Money Transfer&quot; DISABLED=&quot;DISABLED&quot;&gt; &lt;/div&gt;&lt;div class=&quot;form-group&quot;&gt; &lt;label class=&quot;control-label mandatory&quot; for=&quot;message&quot;&gt;Message&lt;/label&gt; &lt;textarea class=&quot;textarea form-control&quot; name=&quot;message&quot; id=&quot;message&quot; cols=&quot;30&quot; rows=&quot;3&quot; maxlength=&quot;5000&quot; DISABLED=&quot;DISABLED&quot; REQUIRED=&quot;REQUIRED&quot;&gt; The Name is XYZ &lt;/textarea&gt;&lt;span class=&quot;mand&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;help-text&quot;&gt;Max. 5000 characters&lt;/span&gt; &lt;/div&gt;'
select convert(XML, NAME) from #temp

Key Changes Made

  • Changed DISABLED to DISABLED="DISABLED" in both the <input> and <textarea> elements
  • Changed REQUIRED to REQUIRED="REQUIRED" in the <textarea> element

Run this corrected code, and your XML conversion should work without parsing errors.

内容的提问来源于stack exchange,提问作者som_1522

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 07:57:46