Skip to content

Commit fd97f04

Browse files
committed
Rename Element.Create to Element.CreateElementContinue
1 parent bf1cb66 commit fd97f04

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

etree.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -764,23 +764,22 @@ func (e *Element) CreateElement(tag string) *Element {
764764
// use in the Element Create function.
765765
type CreateContinuation func(e *Element)
766766

767-
// Create creates a new element with the specified tag (i.e., name) and adds
768-
// it as the last child token of the element e. The tag may include a prefix
769-
// followed by a colon. After creating the element, Create calls the
770-
// continuation function to perform additional actions on the created child
771-
// element.
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.
772771
//
773-
// This method of creating elements is useful when building nested XML
774-
// document from code. For example:
772+
// This method of element creation is particularly useful when building nested
773+
// XML documents from code. For example:
775774
//
776-
// org := doc.Create("organization", func(e *Element) {
777-
// e.Create("person", func(e *Element) {
775+
// org := doc.CreateElementContinue("organization", func(e *Element) {
776+
// e.CreateElementContinue("person", func(e *Element) {
778777
// e.CreateAttr("name", "Mary")
779778
// e.CreateAttr("age", "30")
780779
// e.CreateAttr("hair", "brown")
781780
// })
782781
// })
783-
func (e *Element) Create(tag string, f CreateContinuation) *Element {
782+
func (e *Element) CreateElementContinue(tag string, f CreateContinuation) *Element {
784783
child := e.CreateElement(tag)
785784
f(child)
786785
return child

etree_test.go

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

16331633
func TestContinuations(t *testing.T) {
16341634
doc := NewDocument()
1635-
root := doc.Create("root", func(e *Element) {
1636-
e.Create("child1", func(e *Element) {
1637-
e.Create("grandchild1", func(e *Element) {
1635+
root := doc.CreateElementContinue("root", func(e *Element) {
1636+
e.CreateElementContinue("child1", func(e *Element) {
1637+
e.CreateElementContinue("grandchild1", func(e *Element) {
16381638
e.CreateAttr("attr1", "1")
16391639
e.CreateAttr("attr2", "2")
16401640
})
1641-
e.Create("grandchild2", func(e *Element) {
1641+
e.CreateElementContinue("grandchild2", func(e *Element) {
16421642
e.CreateAttr("attr1", "3")
16431643
e.CreateAttr("attr2", "4")
16441644
})
16451645
})
1646-
e.Create("child2", func(e *Element) {
1647-
e.Create("grandchild1", func(e *Element) {
1646+
e.CreateElementContinue("child2", func(e *Element) {
1647+
e.CreateElementContinue("grandchild1", func(e *Element) {
16481648
e.CreateAttr("attr1", "5")
16491649
e.CreateAttr("attr2", "6")
16501650
})
1651-
e.Create("grandchild2", func(e *Element) {
1651+
e.CreateElementContinue("grandchild2", func(e *Element) {
16521652
e.CreateAttr("attr1", "7")
16531653
e.CreateAttr("attr2", "8")
16541654
})

0 commit comments

Comments
 (0)