Post

XML Template Expression

You can use XML template expression to construct an XML value.

✍ Syntax

XML Template

xml ` BacktickItem* Dollar* `

Here

  • BacktickItem := BacktickSafeChar| BacktickDollarsSafeChar| Dollar* interpolation
  • interpolation := ${ expression }
  • BacktickSafeChar := ^ ( ` | $ )
  • BacktickDollarsSafeChar := $+ ^ ( { | ` | $)
  • Dollar := $

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import ballerina/io;

public function main() {

    string name = "tom";
    int age = 25;
    xml person = xml `
<person>
    <name>${name}</name>
    <age>${age}</age>
</person>`;

    io:println(person);
}

<person>
    <name>tom</name>
    <age>25</age>
</person>
 bal version
Ballerina 2201.6.0 (Swan Lake Update 6)
// Partial Code. Change View  to see full code.
public function main() {
    string name = "tom";
    int age = 25;
    xml person = xml `
<person>
    <name>${name}</name>
    <age>${age}</age>
</person>`;

}
// Highlights Only. Change View  to see full code.
xml person = xml `
<person>
<name>${name}</name>
<age>${age}</age>
</person>`;

XML Template Expression Example

 January 1, 2023

Table of Content

Key Words

XML Template
 January 1, 2023

Table of Content

Key Words


Navigation

Site Settings

Site Theme

Source Code Density