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

Support for custom attributes #27

Open
stephenHartzell opened this issue Oct 28, 2014 · 9 comments
Open

Support for custom attributes #27

stephenHartzell opened this issue Oct 28, 2014 · 9 comments

Comments

@stephenHartzell
Copy link

Maybe this can already be done, but I haven't seen it. Can insert custom attributes other than "type" and "id"?

The reason I bring this up is that this could very easily support converting a json file into a kml file save for that limitation.

@rafaelcanovas
Copy link

I was looking for this also, it seems all dict keys are treated like child nodes, maybe we can get keys starting with '@' (since they're invalid XML node names) to be treated as custom attributes, so we end up with something like:

{
    'checkout': {
        '@currency': 'BRL',
        '@text': 10.5
    }
}
<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <checkout type="dict" currency="BRL">
        10.5
    </checkout>
</root>

We might lose attribute types and will only be possible on dicts.
Is this something like this already possible?

@alberteloyan
Copy link

This would be awesome to have. I need to be able to add 'name' attributes to generate Android externalized string resource files.

Great approach @mstrcnvs, would love to see it implemented.

@ghost
Copy link

ghost commented Sep 1, 2016

+1

@neetjn
Copy link

neetjn commented Feb 17, 2018

Was this ever implemented or at the very least in a fork?

@BowenFu
Copy link

BowenFu commented Mar 6, 2018

Also need it.

@neetjn
Copy link

neetjn commented Mar 6, 2018

@BowenFu I ended up using the xmler package. For user, checkout https://github.com/neetjn/polymath-engineering-challenge/blob/master/polymath/core.py

@BowenFu
Copy link

BowenFu commented Mar 7, 2018

@neetjn Thanks. That is very helpful.

@elebumm
Copy link

elebumm commented Jan 22, 2019

Hi guys,

Crazy to think that this issue has gone back all the way to 2014. I have started developing a solution you can see over on #66. Let me know what you guys think. Feedback is much appreciated.

@javadev
Copy link

javadev commented Jan 17, 2023

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <checkout type="dict" currency="BRL">
        10.5
    </checkout>
</root>

may be converted to json

{
  "checkout": {
    "-type": "dict",
    "-currency": "BRL",
    "#text": "\n        10.5\n    "
  }
}

https://xmltojson.github.io/

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

7 participants