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 namespace support #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Add namespace support #9

wants to merge 8 commits into from

Conversation

Charnelx
Copy link

@Charnelx Charnelx commented Oct 3, 2016

Hi.

I tried to add namespace support for BadgerFish converter.
The main problem i have faced - support for standard xml library and lxml. Their namespace implementation slightly differs so there is no simple methods to support them both in one way.

Because of a lack of experience my code is messy, sorry.

My implementation stands for one idea - give on the output exact thing that were received on the input.

Now examples of use:

  • simple one; default namespace without prefix.
element = fromstring('<root xmlns="http://dot.com"><joe>string</joe></root>')
dict_obj = xmljson.badgerfish.data(element)

print(dict_obj)
>>> OrderedDict([('root', OrderedDict([('@xmlns', {None: 'http://dot.com'}), ('joe', OrderedDict([('@xmlns', {None: 'http://dot.com'}), ('$', 'string')]))]))])

element = xmljson.badgerfish.etree(dict_obj)
print(tostring(element[0]))
>>> b'<root xmlns="http://dot.com"><joe>string</joe></root>'

print(element[0].nsmap) # lxml only!
>>> {None: 'http://dot.com'}
  • both root and child node have namespace prefix; root node have multiple namespaces
element = fromstring('<abc:root xmlns:abc="http://dot.com" xmlns:xyz="http://com.doc"><xyz:joe>string</xyz:joe></abc:root>')
dict_obj = xmljson.badgerfish.data(element)

print(dict_obj)
>>> OrderedDict([('root', OrderedDict([('@xmlns', {'xyz': 'http://com.doc', 'abc': 'http://dot.com'}), ('joe', OrderedDict([('@xmlns', {'xyz': 'http://com.doc'}), ('$', 'string')]))]))])

element = xmljson.badgerfish.etree(dict_obj)
print(tostring(element[0]))
>>> b'<root xmlns:xyz="http://com.doc" xmlns:abc="http://dot.com"><xyz:joe>string</xyz:joe></root>'

print(element[0].nsmap) # lxml only!
>>> {'xyz': 'http://com.doc', 'abc': 'http://dot.com'}

If you have some questions - ask, will be glad to answer.

@sanand0
Copy link
Owner

sanand0 commented Oct 4, 2016

@Charnelx -- thanks a lot for this!

I like the approach you're taking for BadgerFish. Do you have any suggestions on how we could do this for other conventions? We don't necessarily have to implement them. But deciding on their specification can help iron-out any inconsistencies in the BadgerFish namespace convention as well.

Also, you may want to re-work the test cases ensure the Travis checks pass.

@Charnelx
Copy link
Author

Charnelx commented Oct 4, 2016

@sanand0 thanks for having time to look at my code!

Do you have any suggestions on how we could do this for other conventions?

Yes i have an idea of how to add support for other convention types but this needs total code refactory. The main problem is still support for both xml and lxml.

Also, you may want to re-work the test cases ensure the Travis checks pass.

Yes, i'll do that. It's little strange because locally tests pass without errors

@sanand0
Copy link
Owner

sanand0 commented Oct 4, 2016

@Charnelx

So it's just the GData convention that needs namespaces then.

@Charnelx
Copy link
Author

Charnelx commented Oct 4, 2016

@sanand0

Good, i'll look what we can do with GData then.

@sanand0 sanand0 mentioned this pull request Nov 21, 2016
@fireundubh
Copy link

Has there been any more work done to support namespaces in GData?

@sanand0
Copy link
Owner

sanand0 commented Mar 11, 2018

@fireundubh -- unfortunately, I haven't received a pull request subsequently. No work is happening on namespaces that I know of

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

Successfully merging this pull request may close these issues.

3 participants