Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.67 KB

data-accessor-functions.md

File metadata and controls

36 lines (26 loc) · 1.67 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords dev_langs
Data Accessor Functions
Learn how to use the XQuery data-accessor functions fn:data(), fn:string(), and text().
rothja
jroth
03/14/2017
sql
xml
language-reference
data-accessor functions [XQuery]
XML

Data Accessor Functions

[!INCLUDE SQL Server Azure SQL Database]

The topics in this section discuss and provide sample code for the data-accessor functions.

Understanding fn:data(), fn:string(), and text()

XQuery has a function fn:data() to extract scalar, typed values from nodes, a node test text() to return text nodes, and the function fn:string() that returns the string value of a node. Their use can be confusing. The following are guidelines for using them correctly in [!INCLUDEssNoVersion]. The XML instance <age>12</age> is used for the purpose of illustration.

  • Untyped XML: The path expression /age/text() returns the text node "12". The function fn:data(/age) returns the string value "12" and so does fn:string(/age).

  • Typed XML: The expression /age/text() returns a static error for any simple typed <age> element. On the other hand, fn:data(/age) returns integer 12. The fn:string(/age) yields the string "12".

In This Section

See Also

Path Expressions (XQuery)