FOR XML 所要求的 XML 标识符无效

发布于 2024-12-08 16:07:02 字数 496 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随遇而安 2024-12-15 16:07:02

节点名称中包含 £ 不合法 符号,因此即使您可以说服 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.

坏尐絯 2024-12-15 16:07:02

您需要为带有井号的列找到另一个名称,因为这些名称对于 FOR XML 无效。

考虑使用货币缩写,例如 Profit_GBPDelivered_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文