ballerina-lang
ballerina-lang copied to clipboard
[Improvement]: Support a new option to add attributes in XML to Record conversion
Description
Currently we have an option to include namespaces when converting an XML to a record. Similarly add another option to add attributes.
example:
<book>
<title lang="en">string</title>
</book>
Without attributes
@xmldata:Name {value: "book"}
type Book record {
string title;
};
With attributes
type Title record {
string \#content;
@xmldata:Attribute
string lang;
};
@xmldata:Name {value: "book"}
type Book record {
Title title;
};
Describe your problem(s)
No response
Describe your solution(s)
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
We can support following two options for attributes.
- Option1:
Add attributes
As mentioned in this issue description, user can include or exclude attribute with this option. - Option2:
Ignore attribute annotations
where user can remove the attribute annotation only.
XML source:-
<Book>
<title year="2006">Clean Code</title>
<author>R.C Martin</author>
</Book>
Default behaviour
type Data record {|
Title title;
string author;
|};
type Title record {|
@xmldata:Attribute
int year;
string \#content;
|}
Option 1: Remove attribute
type Data record {|
string title;
string author;
|};
Option 2: Ignore attribute annotation
type Data record {|
Title title;
string author;
|};
type Title record {|
int year;
string \#content;
|}
@hasithaa @mindula WDYT should we support both cases or the only the option1
?
Decided to add two options for each of the above mentioned scenarios.
Yes, these are two different options. But if developer decides to ignore attributes, we need to disable add attribute annotation option in the UI.