json2xml
json2xml copied to clipboard
List items with attributes
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
Yes, thanks this would suit for what I want to achieve
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
{
"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>
@javadev what do you mean with your comment? An example of the code behaviour at the moment?
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.
I see @EstherFranssen That your suggestion is similar to option 5 so I think I'll make an attempt at it.
Guys, thanks for all the comments and for providing implementation ideas. I will look into each of these and give my opinion by this weekend, and possibly a PR for it as well.
On Tue, 3 Jan 2023 at 19:53, Jeroendevr @.***> wrote:
I see @EstherFranssen https://github.com/EstherFranssen That your suggestion is similar to option 5 so I think I'll make an attempt at it.
— Reply to this email directly, view it on GitHub https://github.com/vinitkumar/json2xml/issues/163#issuecomment-1369826554, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEDITSKZB4RKZNH36USLKTWQQY7PANCNFSM6AAAAAATBOGOZ4 . You are receiving this because you were mentioned.Message ID: @.***>
-- Thanks and Regards, Vinit Kumar
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.
@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.
Thanks @vinitkumar, @Jeroendevr, this is great!