XMLNAMESPACES declaration
The XMLNAMESPACES declaration constructs namespace declarations from the arguments.
The schema is SYSIBM. The declaration name cannot be specified as a qualified name.
This declaration can only be used as an argument for specific functions such as XMLELEMENT, XMLFOREST and XMLTABLE. The result is one or more XML namespace declarations containing in-scope namespaces for each non-null input value.
- namespace-uri
- Specifies the namespace universal resource identifier (URI) as an SQL character string constant. This character string constant must not be empty if it is used with a namespace-prefix (SQLSTATE 42815).
- namespace-prefix
- Specifies a namespace prefix. The prefix is an SQL identifier
that must be in the form of an XML NCName (SQLSTATE 42634). See the W3C
XML namespace specifications for more details on valid names.
The prefix cannot be
xml
orxmlns
and the prefix must be unique within the list of namespace declarations (SQLSTATE 42635). - DEFAULT namespace-uri
- Specifies the default namespace to use within the scope of this namespace declaration. The namespace-uri applies for unqualified names in the scope unless overridden in a nested scope by another DEFAULT declaration or a NO DEFAULT declaration.
- NO DEFAULT
- Specifies that no default namespace is to be used within the scope of this namespace declaration. There is no default namespace in the scope unless overridden in a nested scope by a DEFAULT declaration.
The data type of the result is XML. The result is an XML namespace declaration for each specified namespace. The result cannot be null.
Examples
Note: XMLNAMESPACES
does not insert blank spaces or new line characters in the output.
All example output has been formatted to enhance readability.
- Example 1: Produce an XML element named adm:employee and
an XML attribute adm:department, both associated with a namespace
whose prefix is adm.
This query produces the following result:SELECT EMPNO, XMLELEMENT( NAME "adm:employee", XMLNAMESPACES( 'http://www.adm.com' AS "adm" ), XMLATTRIBUTES( WORKDEPT AS "adm:department" ), LASTNAME ) FROM EMPLOYEE WHERE JOB = 'ANALYST'
000130 <adm:employee xmlns:adm="http://www.adm.com" adm:department="C01"> QUINTANA</adm:employee> 000140 <adm:employee xmlns:adm="http://www.adm.com" adm:department="C01"> NICHOLLS</adm:employee> 200140 <adm:employee xmlns:adm="http://www.adm.com" adm:department="C01"> NATZ</adm:employee>
- Example 2: Produce an XML element named 'employee', which
is associated with a default namespace, and a sub-element named 'job',
which does not use a default namespace, but whose sub-element named
'department' does use a default namespace.
This query produces the following result:SELECT EMP.EMPNO, XMLELEMENT( NAME "employee", XMLNAMESPACES( DEFAULT 'http://hr.org' ), EMP.LASTNAME, XMLELEMENT( NAME "job", XMLNAMESPACES( NO DEFAULT ), EMP.JOB, XMLELEMENT( NAME "department", XMLNAMESPACES( DEFAULT 'http://adm.org' ), EMP.WORKDEPT ) ) ) FROM EMPLOYEE EMP WHERE EMP.EDLEVEL = 12
000290 <employee xmlns="http://hr.org">PARKER<job xmlns="">OPERATOR <department xmlns="http://adm.org">E11</department></job></employee> 000310 <employee xmlns="http://hr.org">SETRIGHT<job xmlns="">OPERATOR <department xmlns="http://adm.org">E11</department></job></employee> 200310 <employee xmlns="http://hr.org">SPRINGER<job xmlns="">OPERATOR <department xmlns="http://adm.org">E11</department></job></employee>