FOR XML 所要求的 XML 标识符无效
我有一个 sp 返回我:
Select 10 as Visits,5 as [Test_Drives],3 as Orders,'£5000' as [Profit_£],4 as Deliveries,'£6000' as [Delivered_Profit_£]
FOR XML PATH('CONTENT'),ROOT('SOMEROOT')
但是当我使用 ouptut as 时
Dim dr As New SqlDataAdapter(SqlCmd)
Dim tbl As New DataTable
dr.Fill(tbl)
出现错误
列名“Profit_£”包含 FOR XML 要求的无效 XML 标识符; '£'(0x00A3) 是第一个有问题的字符。
问题是我需要有一个原始的列名称。
我该如何解决这个问题呢?
I have a sp which returns me:
Select 10 as Visits,5 as [Test_Drives],3 as Orders,'£5000' as [Profit_£],4 as Deliveries,'£6000' as [Delivered_Profit_£]
FOR XML PATH('CONTENT'),ROOT('SOMEROOT')
But when I use ouptut as
Dim dr As New SqlDataAdapter(SqlCmd)
Dim tbl As New DataTable
dr.Fill(tbl)
I get an error
Column name 'Profit_£' contains an invalid XML identifier as required by FOR XML; '£'(0x00A3) is the first character at fault.
The problem is that I need have a raw name of column.
How can I struggle with that problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
节点名称中包含
£ 不合法
符号,因此即使您可以说服 mssql 允许您这样做,您对生成的 XML 所做的任何操作都可能会被拒绝。如果您想要 XML 并且不关心其格式错误,则必须将常规结果集返回到 .net 应用程序并手动构建 xml 字符串。
最好一开始就不要使用
£
;...作为[Profit_Pounds]
。根据您的需要,FOR XML RAW 会自动将 £ 转义为 _x???姓名。
Its not legal to have a node name containing a
£
symbol, so even if you could persuade mssql to allow you, whatever you did with the resulting XML would probably be rejected.If you want XML and don't care that its badly formed, your going to have to return a regular result set to your .net app and build a string of xml manually.
Better to not use
£
in the first place;... as [Profit_Pounds]
.Depending on what you want, FOR XML RAW would automatically escape the £ to a _x??? name.
您需要为带有井号的列找到另一个名称,因为这些名称对于
FOR XML
无效。考虑使用货币缩写,例如
Profit_GBP
、Delivered_Profit_GBP
。XML 数据格式仅支持非重音 US-ASCII 字符 Az、某些标点符号和数字。明确不支持英镑符号(和欧元)。
You'll need to find another name for the columns with pound signs, as these are not valid for
FOR XML
.Consider using a currency abbreviation, such as
Profit_GBP
,Delivered_Profit_GBP
.The XML data format only supports unaccented US-ASCII characters A-z, some punctuation, and numbers. The pound sign (and Euro) are explicitly not supported.