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

Is there a way to specify a default (prefix-less) namespace? #2

Open
AndrewBennet opened this issue Mar 19, 2019 · 0 comments
Open

Comments

@AndrewBennet
Copy link

Hi there - thanks for providing this library!

Is there a way to specify a default namespace, to be output in the JSON representation without a namespace prefix? If I do not call CodeMirrorSchemaInfoSerializer.SetPrefix(string, string), then my output has all elements prefixed with cmns0:. If I specify the empty string as a prefix, I still have the preceeding :. In my current usage, I would like the output to have no namespace prefixes (since my root XML element will have a default xmlns attribute).

If there is no way to do this at present, I think this could be achieved by modifying ToElementName(SimpleXmlElementRef) to:

private string ToElementName(SimpleXmlElementRef elementRef)
{
  if (string.IsNullOrEmpty(elementRef.Namespace))
    return elementRef.Name;
  string prefix = GetPrefix(elementRef.Namespace);
  if (string.IsNullOrEmpty(prefix))
      return elementRef.Name;
  return string.Format("{0}:{1}", prefix, elementRef.Name);
}

I.e. if a supplied prefix is null or empty, do not specify a prefix on the output. Is this something you could consider adding?

Thanks,
Andrew

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

1 participant