Functions
fromJson | I Converts a JSON object to an XML representation. |
toJson | I Converts an XML object to its JSON representation. |
toRecord | I Converts an XML to its Record representation. |
fromJson
function fromJson(json jsonValue, JsonOptions options) returns xml? | Error
Converts a JSON object to an XML representation.
1json data = {2 name: "John",3 age: 304};5xml? xmlValue = check xmldata:fromJson(data);
Parameters
- jsonValue json
The JSON source to be converted to XML
- options JsonOptions (default {})
The xmldata:JsonOptions
record for JSON to XML conversion properties
toJson
function toJson(xml xmlValue, XmlOptions options) returns json | Error
Converts an XML object to its JSON representation.
1xml xmlValue = xml `<!-- outer comment -->` + xml `<name>supun</name>`;2json jsonValue = check xmldata:toJson(xmlValue);
Parameters
- xmlValue xml
The XML source to be converted to JSON
- options XmlOptions (default {})
The xmldata:XmlOptions
record consisting of the configurations for the conversion
Return Type
(json | Error)The JSON representation of the given XML on success, else returns an xmldata:Error
toRecord
function toRecord(xml xmlValue, boolean preserveNamespaces, typedesc<record {}> returnType) returns returnType | Error
Converts an XML to its Record representation.
1type Person record {2 string name;3};4xml xmlValue = xml `<!-- outer comment -->` + xml `<name>Alex</name>`;5Person|xmldata:Error person = xmldata:toRecord(xmlValue);
Parameters
- xmlValue xml
The XML source to be converted to a Record
- preserveNamespaces boolean (default true)
Instructs whether to preserve the namespaces of the XML when converting
- returnType typedesc<record {}> (default <>)
The typedesc
of the record that should be returned as a result
Return Type
(returnType | Error)The Record representation of the given XML on success, else returns an xmldata:Error