Skip to content

Commit 29c58a3

Browse files
committed
Rename CreateElementContinue to AddElement
1 parent f6baac9 commit 29c58a3

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

etree.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -759,29 +759,23 @@ func (e *Element) CreateElement(tag string) *Element {
759759
return newElement(space, stag, e)
760760
}
761761

762-
// CreateContinuation is a continuation-passing interface for building
763-
// XML documents in a more nested manner. See the description of its
764-
// use in the Element Create function.
765-
type CreateContinuation func(e *Element)
766-
767-
// CreateElementContinue performs the same task as CreateElement but calls
768-
// a continuation function after the child element is created, allowing
769-
// additional actions to be performed on the child element before
770-
// returning.
762+
// AddElement performs the same task as CreateElement but calls a continuation
763+
// function after the child element is created, allowing additional actions to
764+
// be performed on the child element before returning.
771765
//
772766
// This method of element creation is particularly useful when building nested
773767
// XML documents from code. For example:
774768
//
775-
// org := doc.CreateElementContinue("organization", func(e *Element) {
776-
// e.CreateElementContinue("person", func(e *Element) {
769+
// org := doc.AddElement("organization", func(e *Element) {
770+
// e.AddElement("person", func(e *Element) {
777771
// e.CreateAttr("name", "Mary")
778772
// e.CreateAttr("age", "30")
779773
// e.CreateAttr("hair", "brown")
780774
// })
781775
// })
782-
func (e *Element) CreateElementContinue(tag string, f CreateContinuation) *Element {
776+
func (e *Element) AddElement(tag string, cont func(e *Element)) *Element {
783777
child := e.CreateElement(tag)
784-
f(child)
778+
cont(child)
785779
return child
786780
}
787781

etree_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,25 +1632,25 @@ func TestSiblingElement(t *testing.T) {
16321632

16331633
func TestContinuations(t *testing.T) {
16341634
doc := NewDocument()
1635-
root := doc.CreateElementContinue("root", func(e *Element) {
1636-
e.CreateElementContinue("child1", func(e *Element) {
1635+
root := doc.AddElement("root", func(e *Element) {
1636+
e.AddElement("child1", func(e *Element) {
16371637
e.CreateComment("Grandchildren of child #1")
1638-
e.CreateElementContinue("grandchild1", func(e *Element) {
1638+
e.AddElement("grandchild1", func(e *Element) {
16391639
e.CreateAttr("attr1", "1")
16401640
e.CreateAttr("attr2", "2")
16411641
})
1642-
e.CreateElementContinue("grandchild2", func(e *Element) {
1642+
e.AddElement("grandchild2", func(e *Element) {
16431643
e.CreateAttr("attr1", "3")
16441644
e.CreateAttr("attr2", "4")
16451645
})
16461646
})
1647-
e.CreateElementContinue("child2", func(e *Element) {
1647+
e.AddElement("child2", func(e *Element) {
16481648
e.CreateComment("Grandchildren of child #2")
1649-
e.CreateElementContinue("grandchild1", func(e *Element) {
1649+
e.AddElement("grandchild1", func(e *Element) {
16501650
e.CreateAttr("attr1", "5")
16511651
e.CreateAttr("attr2", "6")
16521652
})
1653-
e.CreateElementContinue("grandchild2", func(e *Element) {
1653+
e.AddElement("grandchild2", func(e *Element) {
16541654
e.CreateAttr("attr1", "7")
16551655
e.CreateAttr("attr2", "8")
16561656
})

0 commit comments

Comments
 (0)