Created
September 25, 2023 06:03
-
-
Save ballerina-github-bot/358a01c41a5409460c72a4c1500470f0 to your computer and use it in GitHub Desktop.
examples/xml-from-record-conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/xmldata; | |
// Defines a record type with annotations. | |
@xmldata:Namespace { | |
prefix: "ns", | |
uri: "http://sdf.com" | |
} | |
type Invoice record { | |
int id; | |
Item[] items; | |
@xmldata:Attribute | |
string 'xmlns = "example.com"; | |
@xmldata:Attribute | |
string status?; | |
}; | |
@xmldata:Namespace { | |
uri: "http://example1.com" | |
} | |
type Item record { | |
string itemCode; | |
int count; | |
}; | |
public function main() returns error? { | |
// Creates an `Invoice` record. | |
Invoice data = { | |
id: 1, | |
items: [ | |
{itemCode: "223345", count: 1}, | |
{itemCode: "223300", count: 7} | |
], | |
status: "paid" | |
}; | |
// Converts a `record` representation to its XML representation. | |
xml result = check xmldata:toXml(data); | |
io:println(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment