namespace-uri 함수(XQuery)

$arg에 xs:string으로 지정된 QName의 네임스페이스 URI를 반환합니다.

구문

fn:namespace-uri() as xs:string
fn:namespace-uri($arg as node()?) as xs:string

인수

  • $arg
    네임스페이스 URI 부분이 검색되는 노드 이름입니다.

주의

  • 인수가 생략된 경우 기본값은 컨텍스트 노드입니다.
  • SQL Server에서 인수가 없는 **fn:namespace-uri()**는 상황별 조건자의 컨텍스트에서만 사용할 수 있습니다. 특히 사용 시 대괄호([])로 묶어야 합니다.
  • $arg가 빈 시퀀스인 경우 길이가 0인 문자열이 반환됩니다.
  • $arg가 확장된 QName이 네임스페이스에 없는 요소 또는 특성 노드인 경우 함수는 길이가 0인 문자열을 반환합니다.

이 항목에서는 AdventureWorks 데이터베이스의 다양한 xml 유형 열에 저장된 XML 인스턴스에 대한 XQuery 예를 제공합니다. 이러한 각 열에 대한 개요는 AdventureWorks 데이터베이스의 xml 데이터 형식 표시를 참조하십시오.

1. 특정 노드의 네임스페이스 URI 검색

다음은 형식화되지 않은 XML 인스턴스에 대해 지정된 쿼리입니다. 쿼리 식 namespace-uri(/ROOT[1])은 지정된 노드의 네임스페이스 URI 부분을 검색합니다.

set @x='<ROOT><a>111</a></ROOT>'
SELECT @x.query('namespace-uri(/ROOT[1])')

지정된 QName에 네임스페이스 URI 부분이 없고 로컬 이름 부분만 있는 경우 결과는 길이가 0인 문자열입니다.

다음 쿼리는 형식화된 Instructions xml 열에 대해 지정되었습니다. namespace-uri(/AWMI:root[1]/AWMI:Location[1]) 식은 <root> 요소에 대한 첫 번째 <Location> 요소 자식의 네임스페이스 URI를 반환합니다.

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

다음은 결과입니다.

https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions

2. 조건자의 인수 없이 namespace-uri() 사용

다음 쿼리는 형식화된 CatalogDescription xml 열에 대해 지정되었습니다. 이 식은 네임스페이스 URI가 https://www.adventure-works.com/schemas/OtherFeatures인 모든 요소 노드를 반환합니다. namespace-uri() 함수는 인수 없이 지정되었으며 컨텍스트 노드를 사용합니다.

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

다음은 결과 중 일부입니다.

<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> ...

이전 쿼리의 네임스페이스 URI를 https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain으로 바꿀 수 있습니다. 그런 다음 확장 QName의 네임스페이스 URI 부분이 https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain인 <ProductDescription> 요소의 모든 요소 노드 자식을 검색합니다.

구현 시 제한 사항

제한 사항은 다음과 같습니다.

  • namespace-uri() 함수는 xs:anyURI 대신 xs:string 유형의 항목을 반환합니다.

참고 항목

참조

노드 함수

개념

local-name 함수(XQuery)

도움말 및 정보

SQL Server 2005 지원 받기