
[英]why am I getting this error XML parsing: line 5, character 13, unexpected end of input"
[英]XML parsing: line 1, character 80, unexpected end of input
当我试图运行这个时,我得到了上面的错误。 我已经确定了这个问题 - 这是因为V&amp ; 在描述中,但我不知道如何解决它。 我不能使用替换因为我可能会再次使用不同的字符/单词(例如with& )。 谢谢
declare @x xml
set @x = '<options>
<option>
<code>95544</code>
<description>17&#34;&#32;Star&#32;spoke&#32;alloy&#32;wheels&#32;&#45;&#32;style&#32;393</description>
<monthlycost>0.00</monthlycost>
<allowed />
</option>
<option>
<code>107394</code>
<description>19&#34;&#32;Individual&#32;V&#32;spoke&#32;alloy&#32;wheels&#32;&#45;&#32;Style&#32;626I</description>
<monthlycost>37.13</monthlycost>
<allowed />
</option>
<option>
<code>86469</code>
<description>Adaptive&#32;M&#32;Sports&#32;suspension</description>
<monthlycost>21.09</monthlycost>
<allowed />
</option>
<option>
<code>61202</code>
<description>Metallic&#32;&#45;&#32;Black&#32;sapphire</description>
<monthlycost>8.15</monthlycost>
<allowed />
</option>
<option>
<code>94722</code>
<description>Move&#32;cloth&#32;&#45;&#32;Anthracite</description>
<monthlycost>0.00</monthlycost>
<allowed />
</option>
<option>
<code>11646</code>
<description>Solid&#32;&#45;&#32;Alpine&#32;white</description>
<monthlycost>0.00</monthlycost>
<allowed />
</option>
</options>'
select
pref.value('(code/text())[1]', 'varchar(32)') as Code
,pref.value('(description/text())[1]', 'varchar(80)') as [Description]
,CONVERT(XML,
pref.value('(description/text())[1]', 'varchar(80)')
).value('.', 'varchar(80)') as [DescriptionFixed]
,pref.value('(monthlycost/text())[1]', 'varchar(32)') as MontlyCost
from
@X.nodes('/options/option') AS Options(pref)
问题是你的XML字符串被截断,留下一个不完整的实体/无效字符(注意尾随&
):
19" Individual V spoke alloy wheels - Style&
您只需增加varchar
大小即可解决问题,例如:
,CONVERT(XML,
pref.value('(description/text())[1]', 'varchar(max)')
).value('.', 'varchar(max)') as [DescriptionFixed]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.