xmldata
Module xmldata
ballerina/xmldata Ballerina library
Overview
This module provides APIs to perform conversions between XML and JSON/Ballerina records. It provides APIs to get natural representations of data in XML from JSON and get JSON or Ballerina records data from natural representations of data in XML.
For information on the operations, which you can perform with the xmldata module, see the below Functions.
Functions
fromJson
function fromJson(json jsonValue, JsonOptions options) returns xml?|Error
Converts a JSON object to an XML representation.
json data = { name: "John", age: 30 }; xml? xmlValue = check xmldata:fromJson(data);
Parameters
- jsonValue json - The JSON source to be converted to XML
- options JsonOptions (default {}) - The
xmldata: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.
xml xmlValue = xml `<!-- outer comment -->` + xml `<name>supun</name>`; json 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.
xml xmlValue = xml `<!-- outer comment -->` + xml `<name>Alex</name>`; Person|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
Records
xmldata: JsonOptions
Represents a record type to provide configurations for the JSON to XML conversion.
Fields
- attributePrefix string(default "@") - The attribute prefix to use in the XML representation
- arrayEntryTag string(default "item") - The XML tag to add an element from a JSON array
xmldata: XmlOptions
Provides configurations for converting XML to JSON.
Fields
- attributePrefix string(default "@") - Attribute prefix used in the XML
- preserveNamespaces boolean(default true) - Instructs whether to preserve the namespaces of the XML when converting
Errors
xmldata: Error
Represents the error type of the ballerina/xmldata module. This error type represents any error that can occur during the execution of xmldata APIs.
Import
import ballerina/xmldata;
Metadata
Released date: almost 3 years ago
Version: 2.1.0
License: Apache-2.0
Compatibility
Platform: java11
Ballerina version: slbeta6
GraalVM compatible: Yes
Pull count
Total: 16166
Current verison: 253
Weekly downloads
Keywords
xml
json
Contributors