import ballerina/io;xmlns "http://ballerina.com/aa" as ns0;function main (string[] args) {
xmlns "http://ballerina.com/bb" as ns1;
xmlns "http://ballerina.com/default";
io:println(ns0:foo);
xmlns "http://ballerina.com/updated" as ns0;
io:println(ns0:foo);
}
XML NamespacesBallerina has built-in support for defining and using XML namespaces. |
|
import ballerina/io;
|
|
xmlns "http://ballerina.com/aa" as ns0;
|
|
function main (string[] args) {
|
|
xmlns "http://ballerina.com/bb" as ns1;
|
Namespaces can be declared at package levels as well as at function level. The identifier followed by the ‘as’ keyword is the prefix bound to this namespace name. |
xmlns "http://ballerina.com/default";
|
Namespace declaration without the prefix. This will define a default namespace. |
io:println(ns0:foo);
|
Namespaces can be used for XML qualified names. |
xmlns "http://ballerina.com/updated" as ns0;
io:println(ns0:foo);
}
|
Package level namespaces can be overridden at function level. |
$ ballerina run xml-namespaces.bal
{http://ballerina.com/aa}foo
{http://ballerina.com/updated}foo
|
|