【发布时间】:2014-04-09 05:38:22
【问题描述】:
我正在开发一个 asp.net c# 应用程序。以下XML 以Bookpoint 列作为text 数据类型存储在我的数据库中。
我只需要获取不同元素下的所有<Point> 节点。我正在考虑在 SQL Server 2008 中使用 XQuery 获得所有这些积分
<BreezyCalc xml:space="preserve" xmlns="http://microsoft.com">
<Graph Foreground="#FF000000">
<point>lines added</point>
<Graph/>
<Graph Foreground="#FF000000">
<point>lines added</point>
<point>two added</point>
<point>lines added</point>
<Graph />
<Graph Foreground="#FF000000">
<lines>
<point>lines Removed</point>
<point>lines added</point>
<lines/>
<Graph/>
<BreezyCalc/>
我的表结构
PointID Name BookPoint CreatedDate |
--------|--------------|---------------------------------------------|-------------------------------
1 | categoryname |<BreezyCalc xml:space="preserve" xmlns="http:|2011-04-05 12:28:15.030 |
2 | category1 |<BreezyCalc xml:space="preserve" xmlns="http:|2011-04-05 12:28:15.030 |
这是我期待的结果
1 |lines added
lines added
two added
lines added from firs column
2 |lines added, from second column
我已经完成了这个脚本
Read XML document stored in SQL Server with text datatype?
;WITH XMLNAMESPACES(DEFAULT 'http://microsoft.com')
SELECT
PointID,
BookPoint.value('(/BreezyCalc/Graph/point)[1]', 'varchar(200)')
FROM BooksTable
where id=1
但结果"lines added "
它只给我一个我有任何解决方案去获取所有<point> 节点请帮助或请
否则,谁能告诉我如何获取我的图表数据<point>
【问题讨论】:
-
你为什么使用
[1]?这将只返回第一个point元素。 -
如果这是 XML - 为什么不是
XML列的数据类型?改变它——一旦你这样做了,我们就可以讨论如何获取数据.... -
感谢 Marc_s 的回复,我已将其更改为 xml 类型,那么我如何一次获取所有节点
-
也感谢您编辑我的问题
-
感谢 John Saunders 的回复 [1] 我可以使用什么来获取所有节点我不知道我只是按照上面给出的 url 博客进行操作
标签: sql-server xml sql-server-2008