Skip to content

Commit a775de4

Browse files
committed
Rename AddElement to CreateChild
1 parent 0da9e6a commit a775de4

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

etree.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -752,28 +752,29 @@ func (e *Element) findTermCharDataIndex(start int) int {
752752
}
753753

754754
// CreateElement creates a new element with the specified tag (i.e., name) and
755-
// adds it as the last child token of the element e. The tag may include a
756-
// prefix followed by a colon.
755+
// adds it as the last child of element 'e'. The tag may include a prefix
756+
// followed by a colon.
757757
func (e *Element) CreateElement(tag string) *Element {
758758
space, stag := spaceDecompose(tag)
759759
return newElement(space, stag, e)
760760
}
761761

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.
762+
// CreateChild performs the same task as CreateElement but calls a
763+
// continuation function after the child element is created, allowing
764+
// additional actions to be performed on the child element before returning.
765765
//
766766
// This method of element creation is particularly useful when building nested
767767
// XML documents from code. For example:
768768
//
769-
// org := doc.AddElement("organization", func(e *Element) {
770-
// e.AddElement("person", func(e *Element) {
769+
// org := doc.CreateChild("organization", func(e *Element) {
770+
// e.CreateComment("Mary")
771+
// e.CreateChild("person", func(e *Element) {
771772
// e.CreateAttr("name", "Mary")
772773
// e.CreateAttr("age", "30")
773774
// e.CreateAttr("hair", "brown")
774775
// })
775776
// })
776-
func (e *Element) AddElement(tag string, cont func(e *Element)) *Element {
777+
func (e *Element) CreateChild(tag string, cont func(e *Element)) *Element {
777778
child := e.CreateElement(tag)
778779
cont(child)
779780
return child

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

0 commit comments

Comments
 (0)