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

replace default: with ns1, default2: with ns2: etc. #40

Open
bmix opened this issue Mar 30, 2018 · 2 comments
Open

replace default: with ns1, default2: with ns2: etc. #40

bmix opened this issue Mar 30, 2018 · 2 comments

Comments

@bmix
Copy link

bmix commented Mar 30, 2018

First things first: This is such a great plugin! Wow! Really! I read it on the closed issues (#1), that you did it for a friend, so you may not even appreciate, how nice and convenient this added XPath functionality is! :-) So, thanks a lot, man!

This is not really an important issue, but convention in the XML world seems to be to use the nsN prefix for namespaces, which are anonymous.

So, default:foo would become ns1:foo and default2:bar would become ns2:bar.

I have no backing on this via some specs, it's just from experience by working with XML IDEs and reading some articles on the web. It may be more familiar to XML users.

@keith-hall
Copy link
Collaborator

Hi, thanks for the feedback! Glad to hear that this plugin is useful for you :)

I agree that nsx notation probably makes more sense / will be more familiar to people, thanks for the suggestion. From a cursory glance, I believe the following places will need some tweaks to facilitate this:

  • defaultNamespacePrefix = settings.get('default_namespace_prefix', 'default')
  • "default_namespace_prefix": "default",
  • def unique_namespace_prefixes(namespaces, replaceNoneWith = 'default', start = 1):
    """Given an ordered dictionary of unique namespace prefixes and their URIs in document order, create a dictionary with unique namespace prefixes and their mappings."""
    unique = collections.OrderedDict()
    for key in namespaces.keys():
    if len(namespaces[key]) == 1:
    try_key = key or replaceNoneWith
    unique[try_key] = (namespaces[key][0], key)
    else: # find next available number. we can't just append the number, because it is possible that the new numbered prefix already exists
    index = start - 1
    for item in namespaces[key]: # for each item that has the same prefix but a different namespace
    while True:
    index += 1 # try with the next index
    try_key = (key or replaceNoneWith) + str(index)
    if try_key not in unique.keys() and try_key not in namespaces.keys():
    break # the key we are trying is new
    unique[try_key] = (item, key)
    return unique
    (to always append a number, as opposed to just having ns:foo for example. It may make sense to add an additional setting for this, but maybe I'm just customization crazy!)
  • def xpath_tests():
    (because default is hard-coded in the tests... that'd surely fail if someone tries to run the tests after changing the setting - oops, I didn't think of that when I wrote this!)

Would you be interested in working on this and submitting a PR, @bmix ? If not, I'll try to find some spare time to work on it in the near future.

@bmix
Copy link
Author

bmix commented Apr 1, 2018

Thanks for hints! I will, maybe, slowly, investigate this. I am deep in a website project right now, and never did any Sublime plugin development, so I have to learn a little more about it. However, as this is not an important issue, save your time. ;-) There is no need to act on your side.

Oh, btw, the only "official" reference I found regarding the nsN syntax was this: https://www.w3.org/XML/2008/xsdl-exx/ns1

And I was wrong: The numbering goes: ns0, ns1, ns2, etc.

but maybe I'm just customization crazy!

Yes, that may be in this case! ;-)

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

No branches or pull requests

2 participants