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

Getting an error from fromXml API when xml elements have different namespaces #4434

Closed
kalaiyarasiganeshalingam opened this issue May 10, 2023 · 1 comment · Fixed by ballerina-platform/module-ballerina-xmldata#492
Assignees
Labels
module/xmldata Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DIU Data, IO, and Util packages related issues Type/Bug

Comments

@kalaiyarasiganeshalingam
Copy link
Contributor

kalaiyarasiganeshalingam commented May 10, 2023

Description:
$Subject

Run the following sample to produce the error :

import ballerina/io;
import ballerina/xmldata;

// Defines a record type with annotations.
@xmldata:Namespace {
    prefix: "ns",
    uri: "http://sdf.com"
}
type Invoice record {
    RecordName xs\:id;
    Item[] purchased_item;
    @xmldata:Attribute
    string 'xmlns?;
    @xmldata:Attribute
    string status?;
};

@xmldata:Namespace {
    prefix: "xs",
    uri: "http://sdf.com"
}
type Item record {
    string itemCode;
    int item_count;
};

@xmldata:Namespace {
    prefix: "xs",
    uri: "http://sdf.com"
}
type RecordName record {
    
};

public function main() returns error? {
    xml data = xml `<ns:Invoice xmlns="example.com"
                        xmlns:ns="http://sdf.com" status="paid">?
                        <xs:id xmlns:xs="http://sdf.com">1</xs:id>
                        <purchased_item>
                            <itemCode>223345</itemCode>
                            <item_count>1</item_count>
                        </purchased_item>
                        <purchased_item>
                            <itemCode>223300</itemCode>
                            <item_count>7</item_count>
                        </purchased_item>
                    </ns:Invoice>`;
    Invoice output = check xmldata:fromXml(data);
    io:println(output);
}

Error:

error: XML type mismatch with record type: 'map<json>' value cannot be converted to 'problem_2_1:Invoice': 
                field 'xs:id' in record 'problem_2_1:Invoice' should be of type 'problem_2_1:RecordName', found '"1"'
@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@kalaiyarasiganeshalingam kalaiyarasiganeshalingam added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/xmldata Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DIU Data, IO, and Util packages related issues Type/Bug
Projects
Archived in project
1 participant