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

List items with attributes #163

Open
1 task
Jeroendevr opened this issue Dec 16, 2022 · 10 comments
Open
1 task

List items with attributes #163

Jeroendevr opened this issue Dec 16, 2022 · 10 comments

Comments

@Jeroendevr
Copy link
Contributor

Jeroendevr commented Dec 16, 2022

Concept issue

Is your feature request related to a problem? Please describe.
When creating a xml from a list and wanting to add attributes to it seems impossible.

Describe the solution you'd like
Something that should result in

<transportation-mode xml:lang="nl">Fiets</transportation-mode>
<transportation-mode xml:lang="nl">Bus</transportation-mode>
<transportation-mode xml:lang="en">Bike</transportation-mode>

Describe alternatives you've considered

  • A clear and concise description of any alternative solutions or features you've considered.

Option 1 - Multiple sets of attrs and values after each other

{
  'transportation-mode' : {
      '@attrs': {'xml:lang': 'nl'}, '@val': ['Fiets', 'Bus'],
      '@attrs': {'xml:lang': 'en'}, '@val': ['Bike']
  }
}

Option 2

{
  'transportation-mode' : { 
      ['@attrs': {'xml:lang': 'nl'}, '@val': ['Fiets', 'Bus'] ],
      ['@attrs': {'xml:lang': 'en'}, '@val': ['Bike'] ]
  }
}

Option 3 - For every value an attr with values as list

{
  'transportation-mode' : {
      '@attrs': {'xml:lang': 'nl'}, '@attrs': {'xml:lang': 'nl'}, 
      '@val': ['Fiets', 'Bus'],
      '@attrs': {'xml:lang': 'en'}, 
      '@val': ['Bike']
  }
}

Option 4 - For every value an attr as a sequence in a list

{
  'transportation-mode' : { [
        '@attrs': {'xml:lang': 'nl'} '@val': 'Fiets', 
        '@attrs': {'xml:lang': 'nl'} '@val': 'Bus',
        '@attrs': {'xml:lang': 'en'} '@val': 'Bike'
  ] }
}

Option 5 - For every value an attr as a sequence in a listv2

{
  'transportation-mode' : [
        {
            '@attrs': {'xml:lang': 'nl'},
            '@val': 'Fiets'
        },
        {        
            '@attrs': {'xml:lang': 'nl'},
            '@val': 'Bus'
        },
        {
            '@attrs': {'xml:lang': 'en'},
            '@val': 'Bike'
        }  
   ]
}

Additional context
It sounds similar to issue #146 but I don't want to hijack that issue to promote my own feature request.
@EstherFranssen could you confirm this would be a workable solution?

Edit jan-2023 Updated solution I'd like

@EstherFranssen
Copy link

Yes, thanks this would suit for what I want to achieve

@EstherFranssen
Copy link

EstherFranssen commented Dec 20, 2022

After consideration, it is not completely what I need.

Below a possible solution:

{ 
  'searchword' : [
      {'@attrs': {'xml:lang': 'nl'}, '@val': 'Adembescherming'},
      {'@attrs': {'xml:lang': 'en'}, '@val': 'Breathing protection'}
  ]
}

Which should result in:

<searchword xml:lang="nl">Adembescherming</searchword>
<searchword xml:lang="en">Breathing protection</searchword>

I hope this helps

@javadev
Copy link

javadev commented Jan 2, 2023

{ 
  "vehicle" : {
      "attrs": "transportation-mode", 
      "val": ["Bike", "Bus", "Tram"]
  }
}

may be converted to

<?xml version="1.0" encoding="UTF-8"?>
<vehicle>
  <attrs>transportation-mode</attrs>
  <val>Bike</val>
  <val>Bus</val>
  <val>Tram</val>
</vehicle>

@Jeroendevr
Copy link
Contributor Author

@javadev what do you mean with your comment? An example of the code behaviour at the moment?

@Jeroendevr
Copy link
Contributor Author

Jeroendevr commented Jan 3, 2023

Too many implementation possibilities 🤨. Although I have yet to find out which could be implemented at all, I don't have a strong preference yet.
@vinitkumar Could you give your opinion about a possible implementation 🧐. You possibly have a better understanding about the feasibility.

@Jeroendevr
Copy link
Contributor Author

I see @EstherFranssen That your suggestion is similar to option 5 so I think I'll make an attempt at it.

@vinitkumar
Copy link
Owner

vinitkumar commented Jan 3, 2023 via email

@Jeroendevr
Copy link
Contributor Author

Nice, awesome. I have added a PR with a unit test if we are going for option 5. Let me know if I can do anything else for you.

@Jeroendevr Jeroendevr mentioned this issue Jan 18, 2023
@vinitkumar
Copy link
Owner

@EstherFranssen A new release of json2xml has been released and thanks to the great work of @Jeroendevr, we have list with attributes support live.

Please grab the latest code from https://json2xml.readthedocs.io/en/latest/, https://pypi.org/project/json2xml/3.21.0/ and see if it solves your use case. If there are some bugs, please create a ticket.

@EstherFranssen
Copy link

Thanks @vinitkumar, @Jeroendevr, this is great!

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

4 participants