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

Figure out a way to handle namespaces #7

Open
bombsimon opened this issue Apr 4, 2019 · 0 comments
Open

Figure out a way to handle namespaces #7

bombsimon opened this issue Apr 4, 2019 · 0 comments

Comments

@bombsimon
Copy link
Member

RFC 5730 is heavily dependent on namespaces to perform the proper action over the EPP protocol. Sadly, the Go XML standardlibrary has a lot of known issues.

Some people have tried to work around this but I still haven't found a proper solution. Since I want to implement all the types required for EPP both as a server and a client I need to be able to both marshal and unmarshal the data.

A combination of multiple/wrapped types and go-xml enables me to at least do the marshalling (without proper NS registration though). By wrapping yet another type I can also unmarshal.

Example

type DomainInfoMarshal struct {
    Info DomainInfo `xml:"urn:ietf:params:xml:ns:domain-1.0 command>info>info"`
}

type DomainInfoUnmarshal struct {
    Info DomainInfo `xml:"command>info>info"`
}

type DomainInfo struct {
    Name     DomainInfoName `xml:"name"`
    AuthInfo AuthInfo       `xml:"authInfo,omitempty"
}

Incomming data to be unmarshalled, independent of namespace:

diu := DomainInfoUnmarshal{}

xml.Unmarshal(bytes, &dim)

fmt.Println(dim.Info.Name)

And to generate a domain info request:

dim := DomainInfoMarshal{
    Info: DomainInfo{
        Name: "example.se",
    },
}

b, _ := xml.Marshal(dim)
p, _ := xmltree.Parse(b)

// Traverse P and look for p.Name.Space. If set, create an xmlns:alias and use
// on children by setting child.Name.Local to alias:name

This does not feel like an optimal solution.

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