Skip to content

Commit fc285eb

Browse files
authored
Merge pull request #48 from twpayne/empty
Add EmptyElement
2 parents 6f8afdf + 82757cf commit fc285eb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

kml.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type Element interface {
3838
xml.Marshaler
3939
}
4040

41+
// An EmptyElement is an empty KML element.
42+
type EmptyElement struct{}
43+
4144
// A ParentElement is a KML element with children.
4245
type ParentElement interface {
4346
Element
@@ -61,6 +64,16 @@ func MakeElements[S []T, T Element](s S) []Element {
6164
return elements
6265
}
6366

67+
// Empty returns a new EmptyElement.
68+
func Empty() *EmptyElement {
69+
return &EmptyElement{}
70+
}
71+
72+
// MarshalXML implements encoding/xml.Marshaler.MarshalXML.
73+
func (e *EmptyElement) MarshalXML(*xml.Encoder, xml.StartElement) error {
74+
return nil
75+
}
76+
6477
func encodeElement(encoder *xml.Encoder, startElement xml.StartElement) error {
6578
if err := encoder.EncodeToken(startElement); err != nil {
6679
return err

kml_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ func TestSimpleElements(t *testing.T) {
294294
element: kml.GxIntValue(1),
295295
expected: "<gx:value>1</gx:value>",
296296
},
297+
{
298+
name: "Empty",
299+
element: kml.Empty(),
300+
expected: "",
301+
},
297302
} {
298303
t.Run(tc.name, func(t *testing.T) {
299304
var builder strings.Builder

0 commit comments

Comments
 (0)