xsd2codemirror icon indicating copy to clipboard operation
xsd2codemirror copied to clipboard

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

Open AndrewBennet opened this issue 5 years ago • 0 comments

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

AndrewBennet avatar Mar 19 '19 12:03 AndrewBennet