-
Notifications
You must be signed in to change notification settings - Fork 177
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
Element.Create #141
Comments
implementation package etree
func (e *Element) Create(tag string, f func(*Element)) {
f(e.CreateElement(tag))
} |
in case this is not accepted, here is a wrapper: package etree
import "github.com/beevik/etree"
type Document struct {
*etree.Document
}
func NewDocument() *Document {
var d Document
d.Document = etree.NewDocument()
return &d
}
func (d Document) Element() *Element {
return &Element{&d.Document.Element}
}
type Element struct {
*etree.Element
}
func (e *Element) Create(tag string, f func(*Element)) {
f(&Element{
e.Element.CreateElement(tag),
})
} |
While I understand the motivation for this feature, I'm not sure I agree that the package demands a new API for creating elements and attributes. Your approach is essentially syntactic sugar for the existing API, which doesn't directly support a "nested" style of element creation. I think I prefer keeping the API surfaces concise so there is less ambiguity in how to do things. |
that's a shame. I modeled the example above from here: https://github.com/beevik/etree#creating-an-xml-document but instead of four top level declarations:
you have one:
also note I modeled this pattern from packages in
|
After giving it more thought (and seeing the precedent you described in |
note this style is also documented here |
Element should have a Create method or similar, to allow for more natural creation of nested values
The text was updated successfully, but these errors were encountered: