Swan Lake Beta3 is here.
import ballerina/io;

string url = "https://ballerina.io";

xml content = 
    // `xml` values can be constructed using an XML template expression.
    // Attribute values can have `string` values as interpolated expressions.
    xml `<a href="${url}">Ballerina</a> is an <em>exciting</em> new language!`;

// Interpolated expressions can also be in content (`xml` or `string` values).
xml p = xml `<p>${content}</p>`;

public function main() {
    io:println(content);
    io:println(p);
}

XML Templates

xml values can be constructed using an XML template expression. Phase 2 processing for xml template tag parses strings using the XML 1.0 Recommendation’s grammar for content (what XML allows between a start-tag and an end-tag). Interpolated expressions can be in content (xml or string values) or in attribute values (string values).

import ballerina/io;
string url = "https://ballerina.io";
xml content = 
    xml `<a href="${url}">Ballerina</a> is an <em>exciting</em> new language!`;

xml values can be constructed using an XML template expression. Attribute values can have string values as interpolated expressions.

xml p = xml `<p>${content}</p>`;

Interpolated expressions can also be in content (xml or string values).

public function main() {
    io:println(content);
    io:println(p);
}
bal run xml_templates.bal
<a href="https://ballerina.io">Ballerina</a> is an <em>exciting</em> new language!
<p><a href="https://ballerina.io">Ballerina</a> is an <em>exciting</em> new language!</p>
import ballerina/io;

string url = "https://ballerina.io";

xml content = 
    // `xml` values can be constructed using an XML template expression.
    // Attribute values can have `string` values as interpolated expressions.
    xml `<a href="${url}">Ballerina</a> is an <em>exciting</em> new language!`;

// Interpolated expressions can also be in content (`xml` or `string` values).
xml p = xml `<p>${content}</p>`;

public function main() {
    io:println(content);
    io:println(p);
}

XML Templates

xml values can be constructed using an XML template expression. Phase 2 processing for xml template tag parses strings using the XML 1.0 Recommendation’s grammar for content (what XML allows between a start-tag and an end-tag). Interpolated expressions can be in content (xml or string values) or in attribute values (string values).

import ballerina/io;
string url = "https://ballerina.io";
xml content = 
    xml `<a href="${url}">Ballerina</a> is an <em>exciting</em> new language!`;

xml values can be constructed using an XML template expression. Attribute values can have string values as interpolated expressions.

xml p = xml `<p>${content}</p>`;

Interpolated expressions can also be in content (xml or string values).

public function main() {
    io:println(content);
    io:println(p);
}
bal run xml_templates.bal
<a href="https://ballerina.io">Ballerina</a> is an <em>exciting</em> new language!
<p><a href="https://ballerina.io">Ballerina</a> is an <em>exciting</em> new language!</p>
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand