Namespaces
The shell maintains a set of active globally declared namespaces. The scope of the namespaces is the same as environment variables.
The syntax and meaning is similar to the xquery "declare namespace" command (except that the uri need not be quoted).
Declared namespaces interact with the builtin <[ ]> syntax as well as the xpath and xquery commands. The xslt command does not support global namespace declarations because the xslt specs do not provide for external namespace declarations, rather all namespaces must be part of the xslt document.
All global namespaces are pre-declared for these commands.
A Namespace can be declared using the syntax
declare namespace prefix=uri
And the list of currently active namespaces can be retrieved with
declare namespace
Example
$ declare namespace xmlsh=http://www.xmlsh.org/namespaces/xmlsh $ declare namespace xmlsh=http://www.xmlsh.org/namespaces/xmlsh
Global namespace declarations are pre-declared in all <[]> , xquery, and xpath expressions.
For example
$ declare namespace test=http://www.example.org/test $ echo <[<test:foo/>]> <test:foo xmlns:test="http://www.example.org/test"/>
$ xpath -i <[ document{ <test:foo/> } ]> /test:foo <test:foo xmlns:test="http://www.example.org/test"/>
$ xquery -i <[ document{ <test:foo/> } ]> /test:foo <test:foo xmlns:test="http://www.example.org/test"/>
To undefine a global namespace in the current context use the syntax
declare namespace prefix=
default namespace
The default namespace can be declared by omiting the "prefix=". The default namespace passed to all xml oriented commands and is added to generated xml elements with no namespace.
$ declare namespace http://test.xmlsh.org/namespace $ echo <[ <foo/> ]> <foo xmlns="http://test.xmlsh.org/namespace"/>
The default namespace can be unset by using the empty string for the uri
$ declare namespace ''
xmlns variables
As a syntactic convenience namespaces may also be declared similarly to XML attributes by assigning a variable named "xmlns:<prefix>".This assignement may be used as the prefix to a simple command to temporarily override namespaces for a single command invocation.
xmlns:c=http://www.test.org/test some_command
Has the identical effect of
( declare namespace c=http://www.test.org/test some_command some_command )
CommandDeclare