The XMLNSC parser provides full support for namespaces.
The XMLNSC parser uses the following field types to represent namespace declarations. Use the field type constants that are listed in this table when you create namespace declarations in the message tree.
XML construct | XMLNSC field type constant | Value |
---|---|---|
Namespace declaration |
|
|
XML construct | XMLNSC field type constant | Purpose |
---|---|---|
Namespace declaration | XMLNSC.NamespaceDecl | Matches namespace declarations in both single and double quotation marks |
DECLARE space1 NAMESPACE 'namespace1';
SET OutputRoot.XMLNSC.space1:root.(XMLNSC.NamespaceDecl)xmlns:ns1 = space1;
SET OutputRoot.XMLNSC.space1:root.space1:example = 'ABCDE';
This
creates the following XML message: <ns1:root xmlns:ns1="namespace1">
<ns1:example>ABCDE</ns1:example>
</ns1:root>
Note that the NAMESPACE constant space1 is
just a local variable in the ESQL; it does not affect the namespace
prefix ns1 that is defined by the NameSpaceDecl element
and appears in the output message. However, as shown here, space1 can be used to initialize the NameSpaceDecl for ns1. This avoids the need to duplicate the namespace URI ('namespace1' in this example), which in practice is typically a much longer string.
DECLARE space1 NAMESPACE 'namespace1';
SET OutputRoot.XMLNSC.space1:root.(XMLNSC.NamespaceDecl)xmlns = space1;
SET OutputRoot.XMLNSC.space1:root.space1:example = 'ABCDE';
This
creates the following XML message: <root xmlns="namespace1">
<example>ABCDE</example>
</root>
Note that the syntax elements root and example must
have a non-empty namespace. The default namespace declaration means
that any child element without a prefix is in the namespace namespace1. DECLARE space1 NAMESPACE 'namespace1';
SET OutputRoot.XMLNSC.root.(XMLNSC.NamespaceDecl)xmlns = space1;
SET OutputRoot.XMLNSC.root.example = 'ABCDE';
This example
causes the XMLNSC parser to issue the message BIP5014 when
it attempts to create the message tree. The elements root and example are
both within the scope of the default namespace declaration; therefore,
in ESQL, these elements must be qualified by a namespace prefix bound
to that namespace.SET OutputRoot.(XMLNSC.DoubleNamespaceDecl)xmlns:ns2 = space1;
This
example of a SET statement creates a namespace declaration with the
name ns2 in the namespace xmlns.CREATE LASTCHILD OF OutputRoot IDENTITY (XMLNSC.DoubleNamespaceDecl)xmlns:ns2 VALUE space1;
CREATE LASTCHILD OF OutputRoot TYPE XMLNSC.DoubleNamespaceDecl NAMESPACE 'xmlns' NAME 'ns2' VALUE space1;
These
examples of a CREATE statement also create a namespace declaration
with the name ns2 in the namespace xmlns.CREATE LASTCHILD OF OutputRoot TYPE XMLNSC.DoubleNamespaceDecl NAME 'xmlns:ns2' VALUE space1;