ad alanı-uri işlev (XQuery)
URI değerini belirtilen QName ad alanını döndürür $argolarak bir XS.
Sözdizimi
fn:namespace-uri() as xs:string
fn:namespace-uri($arg as node()?) as xs:string
fn:namespace-uri() as xs:string
fn:namespace-uri($arg as node()?) as xs:string
Bağımsız değişkenler
- $arg
Düğüm adı, ad alanı URI bölümü alınır.
Açıklamalar
Bağımsız değişken atlanırsa, varsayılan bağlam düğümdür.
SQL Server, fn:namespace-uri() olmadan bağımsız değişken yalnızca içerik bağımlı yüklemi içeriğinde kullanılabilir. Özellikle, o sadece ayraçlar ([]) içinde kullanılabilir.
Eğer $argboş sırası ise sıfır uzunluklu dize döndürdü.
Eğer $argbir öğe veya öznitelik düğümü olan Genişletilmiş-QName olmayan bir ad alanında, işlevi ise sıfır uzunluklu dize döndürür
Örnekler
Bu konu çeşitli depolanan xml örnekleri karşı XQuery örnekler sağlar xml AdventureWorks veritabanındaki sütunları yazın. Bu sütunlar genel bakış için bkz: DEL - xml Data Type Representation in the AdventureWorks2008R2 Database.
A.Ad alanı URI belirli bir düğümün almak
Aşağıdaki sorgu yazılmamış xml örneği karşı belirtildi. Sorgu ifadesi namespace-uri(/ROOT[1]), belirtilen düğüm ad alanı URI bölümü alır.
set @x='<ROOT><a>111</a></ROOT>'
SELECT @x.query('namespace-uri(/ROOT[1])')
set @x='<ROOT><a>111</a></ROOT>'
SELECT @x.query('namespace-uri(/ROOT[1])')
Belirtilen QName ad alanı URI bölümü ancak yalnızca yerel ad parçası olmadığından, sıfır uzunluklu bir dize sonucudur.
Yazılı talimatları karşı belirtilen aşağıdaki sorgu xml sütun. İfade, namespace-uri(/AWMI:root[1]/AWMI:Location[1]), ad alanı URI ilk döner <Location>öğe alt <root>öğesi.
SELECT Instructions.query('
declare namespace AWMI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions" ;
namespace-uri(/AWMI:root[1]/AWMI:Location[1])') as Result
FROM Production.ProductModel
WHERE ProductModelID=7
SELECT Instructions.query('
declare namespace AWMI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions" ;
namespace-uri(/AWMI:root[1]/AWMI:Location[1])') as Result
FROM Production.ProductModel
WHERE ProductModelID=7
Sonuç şudur:
https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions
https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions
B.Namespace-uri() bağımsız değişken olmadan bir yüklemi kullanma
Aşağıdaki sorgu karşı CatalogDescription yazılı xml sütun belirtildi. İfade döndürür öğe düğümleri, ad alanı URI olduğunu https://www.adventure-works.com/schemas/OtherFeatures. Ad -uri() işlevi bağımsız değişken belirtildiğinde ve içerik düğümü kullanır.
SELECT CatalogDescription.query('
declare namespace p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/p1:ProductDescription//*[namespace-uri() = "https://www.adventure-works.com/schemas/OtherFeatures"]
') as Result
FROM Production.ProductModel
WHERE ProductModelID=19
SELECT CatalogDescription.query('
declare namespace p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/p1:ProductDescription//*[namespace-uri() = "https://www.adventure-works.com/schemas/OtherFeatures"]
') as Result
FROM Production.ProductModel
WHERE ProductModelID=19
Bu kısmi bir sonucudur:
<p1:wheel xmlns:p1="https://www.adventure-works.com/schemas/OtherFeatures">High performance wheels.</p1:wheel>
<p2:saddle xmlns:p2="https://www.adventure-works.com/schemas/OtherFeatures">
<p3:i xmlns:p3="http://www.w3.org/1999/xhtml">Anatomic design</p3:i> and made from durable leather for a full-day of riding in comfort.</p2:saddle>
…
<p1:wheel xmlns:p1="https://www.adventure-works.com/schemas/OtherFeatures">High performance wheels.</p1:wheel>
<p2:saddle xmlns:p2="https://www.adventure-works.com/schemas/OtherFeatures">
<p3:i xmlns:p3="http://www.w3.org/1999/xhtml">Anatomic design</p3:i> and made from durable leather for a full-day of riding in comfort.</p2:saddle>
…
Sen-ebilmek değişmek önceki sorguda ad alanı URI için https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain. Daha sonra tüm öğe düğümü alt alacaksınız <ProductDescription> öğesi olan Genişletilmiş QName ad alanı URI bölümü olan https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain.
Uygulama kısıtlamaları
Bu sınırlamalar şunlardır:
- Namespace-uri() işlevi türü xs anyURI yerine örneklerini döndürür.