import ballerina/io;function main (string[] args) {
xml x1 = xml `<book>The Lost World</book>`;
io:println(x1);
xml x2 = xml `Hello, world!`;
io:println(x2);
xml x3 = xml `<!--I am a comment-->`;
io:println(x3);
xml x4 = xml `<?target data?>`;
io:println(x4);
xml x5 = x1 + x2 + x3 + x4;
io:println("\nResulting XML sequence:");
io:println(x5);
}
XMLThe XML type in Ballerina represents a sequence of zero or more XML items. Each item can be an element, a text, a comment or a processing instruction. |
|
import ballerina/io;
|
|
function main (string[] args) {
|
|
xml x1 = xml `<book>The Lost World</book>`;
io:println(x1);
|
XML element. Can only have one root element. |
xml x2 = xml `Hello, world!`;
io:println(x2);
|
XML text. |
xml x3 = xml `<!--I am a comment-->`;
io:println(x3);
|
XML comment. |
xml x4 = xml `<?target data?>`;
io:println(x4);
|
XML processing instruction |
xml x5 = x1 + x2 + x3 + x4;
io:println("\nResulting XML sequence:");
io:println(x5);
}
|
Multiple XML items can be combined to form a sequence of XML. The resulting sequence is again an XML on its own. |
$ ballerina run xml.bal
<book>The Lost World</book>
Hello, world!
<!--I am a comment-->
<?target data?>
|
|
Resulting XML sequence:
<book>The Lost World</book>Hello, world!<!--I am a comment--><?target data?>
|
|