因此,我从SQL Server2000DB中提取数据,然后使用FOR XML AUTO将其转换为XML。
我得到的XML如下所示。
<Order OrderNumber="2000004" DeliveryPickupCharge="5.9900" SalesTaxTotal="0.0000" SubTotal="0.0000" Total="5.9900">
<Customer FirstName="Anthony" LastName="Caporale">
<Product ProductName="Paper Towels">
<OrderItem ItemQuantity="1" ItemPrice="8.5900" Total="8.5900" />
</Product>
<Product ProductName="Bathroom Tissue - Giant Roll">
<OrderItem ItemQuantity="2" ItemPrice="7.1500" Total="14.3000" />
</Product>
<Product ProductName="Napkins - 1-Ply">
<OrderItem ItemQuantity="1" ItemPrice="3.4900" Total="3.4900" />
</Product>
<Product ProductName="Facial Tissues - 2-Ply - White">
<OrderItem ItemQuantity="2" ItemPrice="2.0500" Total="4.1000" />
</Product>
<Product ProductName="Anti-Perspirant & Deodorant - Ultra DryCool Rush">
<OrderItem ItemQuantity="2" ItemPrice="3.5900" Total="7.1800" />
</Product>
<Product ProductName="Flushable Wipes - Fresh Mates Cloths - Refill">
<OrderItem ItemQuantity="2" ItemPrice="2.9500" Total="5.9000" />
</Product>首先,在2000中没有root (“随便”),那么有没有办法在T-SQL中添加一个根节点呢?还有,有没有办法把所有的产品都包装在一个产品标签里呢?我不太明白为什么返回的XML格式如此糟糕。如果我使用的是SQL2005,我可以稍微修改一下。不幸的是,我现在被2000卡住了。
谢谢
发布于 2009-08-14 18:38:46
您可以使用FOR XML EXPLICIT模式随心所欲地操作XML。我认为它比AUTO (或2k5路径)要复杂得多,但一旦你开始使用它,它就会工作得很好。
发布于 2009-12-22 20:04:57
据我所知,在2005年,使用嵌套的selects允许您将多个结果嵌入到一个核心标记中(产品中的多个产品),同时封装的seelect也被声明为XML AUTO。
您还可以使用这种技术,通过使用一个大型嵌套select将所有内容包装在一个根标记中。
https://stackoverflow.com/questions/1279443
复制相似问题