Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mindula opened this issue Apr 29, 2024 · 3 comments · Fixed by #42989
Closed

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

mindula opened this issue Apr 29, 2024 · 3 comments · Fixed by #42989
Assignees
Labels
Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement userCategory/Compilation

Comments

@mindula
Copy link
Contributor

mindula commented Apr 29, 2024

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

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Apr 29, 2024
@mindula mindula added Team/LanguageServer Language Server Implementation related issues. #Compiler and removed needTriage The issue has to be inspected and labeled manually labels Apr 29, 2024
@mindula mindula self-assigned this May 7, 2024
@prakanth97
Copy link
Contributor

prakanth97 commented May 7, 2024

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?

@mindula
Copy link
Contributor Author

mindula commented May 27, 2024

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

@hasithaa
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/LanguageServer Language Server Implementation related issues. #Compiler Type/Improvement userCategory/Compilation
Projects
Status: Done
4 participants