wso2 / ballerina-vscode

To keep Ballerina VSCode plugin related issues, discussions, etc.
Apache License 2.0
41 stars 20 forks source link

Ignore XML namespaces doesn't work in the new XML import tool #560

Closed hasithaa closed 2 months ago

hasithaa commented 2 months ago

Tested with bellow XML. Even though I opt-out add namespaces, it generates the records with the XML namespace elements.

<Orders xmlns="www.example.com/orders">
  <order xmlns="www.example.com/order">
    <id>001</id>
    <customer xmlns="www.example.com/customer" loyalty="premium" optedInNewsLetter="true">
      <firstName>John</firstName>
      <lastName>Doe</lastName>
      <email>john.doe@example.com</email>
      <id>1001</id>
    </customer>
    <items xmlns="www.example.com/items">
      <item id="a1">
        <name>Widget A</name>
        <quantity>2</quantity>
        <price>15.00</price>
      </item>
      <item id="b2">
        <name>Gadget B</name>
        <quantity>1</quantity>
        <price>25.00</price>
      </item>
    </items>
    <total>55.00</total>
  </order>
  <order xmlns="www.example.com/order">
    <id>002</id>
    <customer xmlns="www.example.com/customer" loyalty="regular" optedInNewsLetter="false">
      <firstName>Jane</firstName>
      <lastName>Smith</lastName>
      <email>jane.smith@example.com</email>
      <id>1002</id>
    </customer>
    <items xmlns="www.example.com/items">
      <item id="c3">
        <name>Tool C</name>
        <quantity>3</quantity>
        <price>10.00</price>
      </item>
      <item id="d4">
        <name>Device D</name>
        <quantity>1</quantity>
        <price>40.00</price>
      </item>
    </items>
    <total>70.00</total>
  </order>
  <order xmlns="www.example.com/order">
    <id>003</id>
    <customer xmlns="www.example.com/customer" loyalty="new" optedInNewsLetter="true">
      <firstName>Alice</firstName>
      <lastName>Brown</lastName>
      <email>alice.brown@example.com</email>
      <id>1003</id>
    </customer>
    <items xmlns="www.example.com/items">
      <item id="e5">
        <name>Accessory E</name>
        <quantity>2</quantity>
        <price>5.00</price>
      </item>
      <item id="f6">
        <name>Supplement F</name>
        <quantity>4</quantity>
        <price>8.00</price>
      </item>
    </items>
    <total>54.00</total>
  </order>
</Orders>

Generated record is.

import ballerina/data.xmldata;
@xmldata:Namespace {uri: "www.example.com/customer"}
type Customer record {
    string firstName;
    string lastName;
    string email;
    int id;
    @xmldata:Attribute
    string loyalty;
    @xmldata:Attribute
    string optedInNewsLetter;
};

type Item record {
    string name;
    int quantity;
    decimal price;
    @xmldata:Attribute
    string id;
};

@xmldata:Namespace {uri: "www.example.com/items"}
type Items record {
    Item[] item;
};

@xmldata:Namespace {uri: "www.example.com/order"}
type Order record {
    int id;
    Customer customer;
    Items items;
    decimal total;
};

@xmldata:Namespace {uri: "www.example.com/orders"}
type Orders record {
    Order[] 'order;
};
hasithaa commented 2 months ago

@mindula @prakanth97 I think this is a problem with the backend.

mindula commented 2 months ago

This is small bug from our side, I've already added the fix to my implementation. I will update the PR. #42589