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

Feature/add namespace #109

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

Conversation

carolinasolfernandez
Copy link
Contributor

@carolinasolfernandez carolinasolfernandez commented Jun 5, 2020

New config for allowing to add a namespace tag to struct
Issue #12

@droyo
Copy link
Owner

droyo commented Jun 9, 2020

So if I understand, this creates an xmlns:<QNAME> attribute, then hard-codes QNAME into the name of each xml element in the struct. It's a clever way to work around the lack of qname support in the encoding/xml marshaller.

The provided example works great, and the result can be marshalled back into the expected XML. I have a few concerns, though:

  • If XmlNS is not populated, and you Marshal the type, it will not have a namespace defined.

  • The example is a little simple and I don't know if this feature would work with a more complex schema. Imagine a bad schema that uses different prefixes for the same target NS in different parts of the schema:

Or what if the targetNamespace does not have a prefix defined in any xmlns attributes in the source schema? It's not strictly required. I tried removing it from your example and this is the result:

type Book struct {
	XMLNs  string `xml:"xmlns:,attr,omitempty"`
	Title  string `xml:":title"`
	Author string `xml:":author"`
}

type Library struct {
	XMLNs string `xml:"xmlns:,attr,omitempty"`
	Book  string `xml:":book"`
}

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.

2 participants