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

Add Multiple NameSpaces for a XML Element #178

Closed
LogeswaranRamasamy opened this issue Sep 7, 2023 · 4 comments
Closed

Add Multiple NameSpaces for a XML Element #178

LogeswaranRamasamy opened this issue Sep 7, 2023 · 4 comments

Comments

@LogeswaranRamasamy
Copy link

LogeswaranRamasamy commented Sep 7, 2023

I am trying to configure multiple namespaces to a XML Element inorder but couldn't find a option to achieve it using Xml Serialization.

Current code:

@Serializable
    @XmlSerialName("breakfast_menu", "breakfast", "b")
    data class FoodMenu (
        @XmlSerialName("food", "", "" )
        var foodList : MutableList<Food> ?= null
    )

Trying to achieve the Below which doesn't seem possible:

@Serializable
  @XmlSerialName("breakfast_menu", "breakfast", "b")
  @XmlSerialName("lunch_menu", "lunch", "l")
  data class FoodMenu (
      @XmlSerialName("food", "", "" )
      var foodList : MutableList<Food> ?= null
  )

Is there any option to achieve it ? If so, how to achieve the same ?
Else is there any alternate workaround to achieve the same ?

@LogeswaranRamasamy LogeswaranRamasamy changed the title Add Multiple NameSpaces for a Element Add Multiple NameSpaces for a XML Element Sep 7, 2023
@pdvrieze
Copy link
Owner

pdvrieze commented Sep 8, 2023

There are two separate ways of naming supported. One is for the type. Types only have a single name (although you could filter your reader to switch names). However, you can also specify the name in the use context (on the properties), in which case the default policy uses that as the priority.

For top-level you can pass along the root tag name to use, and do it that way. For reading the top level tag is automatically detected from the xml if you don't specify it.

A final thing you may want to do is to introduce some namespaces. If you use the @XmlNamespaces annotation you can specify the namespaces to be generated for that tag (which means your xml is not polluted with all kinds of namespace attributes all over the place).

@pdvrieze
Copy link
Owner

This should now be supported using a namespaces annotation.

@Morteza-Rastgoo
Copy link

@pdvrieze Can't find the XmlNamespaces or namespaces annotations. Could you please elaborate?

@pdvrieze
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants