TAILIEUCHUNG - Microsoft SQL Server 2005 Developer’s Guide- P26

Microsoft SQL Server 2005 Developer’s Guide- P26:SQL Server 2005 is a feature-rich release that provides a host of new tools and technologies for the database developer. This book is written to help database developers and DBAs become productive immediately with the new features and capabilities found in SQL Server 2005. | Chapter 7 Developing with XML 229 Querying a Single Element The preceding example showed how to query all of the nodes from a parent node. This example illustrates querying a single node DECLARE @x xml SET @x Myroot Element1 One Element1 Element2 Two Element2 Myroot SELECT @ Myroot Element1 Each level in the XML document hierarchy is closed by the symbol. Here the XQuery returns the value of just the Elementl node as is shown in the following listing Element1 One Element1 1 row s affected Querying Single Element Values Unlike T-SQL XQuery also has the capability to query for single sets of node values according to their predicate or position in the set. The following listing shows how to retrieve the first value from the Element2 node DECLARE @x xml SET @x Myroot Element1 One Element1 Element2 Two Element2 Myroot SELECT @ Myroot Element2 1 In this example the hierarchy of nodes is placed within parenthesis. The desired node number follows enclosed in brackets. You can see the results in the following listing Element2 Two Element2 1 row s affected Querying Typed XML Typed XML . XML that has an associated schema requires that you declare the appropriate namespace in order to retrieve the nodes from the XML document. The following listing illustrates an XQuery that queries the sample MyXMLDocs table 230 Microsoft SQL Server 2005 Developer s Guide that was used in the earlier examples. The MyXMLDoc column in this table contains typed XML. SELECT declare namespace tns http MyXMLDocSchema tns MyXMLDoc . As MyXMLBody FROM MyXMLDocs The declare namespace directive creates a namespace named tns and assigns that namespace the value of http MyXMLDocSchema. This value must match the namespace from the schema. The XQuery needs to preface the node names with the namespace. You can see the results in the following listing MyXMLDoc xmlns http MyXMLDocSchema DocumentID 1 DocumentID DocumentBody Modified Body DocumentBody MyXMLDoc MyXMLDoc xmlns http

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.