xml自动输出时存在空格问题的字段名称
我的sql非常简单,
当我执行此sql时,选择ID为[员工ID],EmpName为[员工姓名],Sal为[薪水] from Emp FOR XML AUTO, ELEMENTS, ROOT('customers')
然后我得到输出xml 格式。 xml 输出是
<customers>
<Emp>
<Employee_x0020_ID>1</Employee_x0020_ID>
<Employee_x0020_Name>Tridip</Employee_x0020_Name>
<Salary>2500</Salary>
</Emp>
<Emp>
<Employee_x0020_ID>2</Employee_x0020_ID>
<Employee_x0020_Name>Ari</Employee_x0020_Name>
<Salary>4000</Salary>
</Emp>
<Emp>
<Employee_x0020_ID>3</Employee_x0020_ID>
<Employee_x0020_Name>Dibyendu</Employee_x0020_Name>
<Salary>3500</Salary>
</Emp>
</customers>
如果您看到 xml 字段名称那么您可以理解字段名称是动态生成的 由于空间。
my sql is very simple
select ID as [Employee ID], EmpName as [Employee Name], Sal as [Salary] from Emp FOR XML AUTO, ELEMENTS, ROOT('customers')
when i execute this sql then i am getting output in xml format. the xml output is
<customers>
<Emp>
<Employee_x0020_ID>1</Employee_x0020_ID>
<Employee_x0020_Name>Tridip</Employee_x0020_Name>
<Salary>2500</Salary>
</Emp>
<Emp>
<Employee_x0020_ID>2</Employee_x0020_ID>
<Employee_x0020_Name>Ari</Employee_x0020_Name>
<Salary>4000</Salary>
</Emp>
<Emp>
<Employee_x0020_ID>3</Employee_x0020_ID>
<Employee_x0020_Name>Dibyendu</Employee_x0020_Name>
<Salary>3500</Salary>
</Emp>
</customers>
if u see the xml filed name then u can understand that field name is generated dynamically
due to space. <Employee_x0020_ID>1</Employee_x0020_ID> this is dynamically generated but i want it should be generated like <Employee ID>1</Employee ID>. i want space should be maintain in the xml filed name. so please tell me what to do........thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 W3Schools 的 XML 元素:
(强调已添加)
From XML Elements at W3Schools:
(Emphasis added)
我想这是同一个问题?
FOR XML AUTO 和列名称对于SQL Server 2005中的空间问题
答案是一样的。 XML 标记名称中不能有空格。
I guess this is the same question?
FOR XML AUTO and column name with space problem in SQL Server 2005
The answer is the same. You can not have a space in a XML tag name.
以下是您正在寻找的假装为 XML 的输出。
您甚至无法在任何解析器中将其转换为 XML(至少不应该——在 SQL Server 中不会)。
输出(为了清晰起见,重新格式化 - SQL Server 在一行上返回所有内容)
Here is the output you are looking for that pretends to be XML.
You won't even be able to cast it to XML in any parser (at least it shouldn't - it won't in SQL Server).
Output (reformatted for clarity - SQL Server returns it all on one line)