ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Improvement]: Support a new option to add attributes in XML to Record conversion

Open mindula opened this issue 9 months ago • 1 comments

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

mindula avatar Apr 29 '24 05:04 mindula

We can support following two options for attributes.

  1. Option1: Add attributes As mentioned in this issue description, user can include or exclude attribute with this option.
  2. 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?

prakanth97 avatar May 07 '24 08:05 prakanth97

Decided to add two options for each of the above mentioned scenarios.

mindula avatar May 27 '24 08:05 mindula

Yes, these are two different options. But if developer decides to ignore attributes, we need to disable add attribute annotation option in the UI.

hasithaa avatar May 27 '24 13:05 hasithaa