forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
display_xml.go
58 lines (44 loc) · 1.06 KB
/
display_xml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"encoding/xml"
"fmt"
"os"
)
type displayXML struct {
}
// MarshalXML converts a MapSS map type into an XML representation. This is
// required because the XML package is unable to deal with maps itself.
func (m MapSS) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
tokens := []xml.Token{start}
for key, value := range m {
t := xml.StartElement{
Name: xml.Name{
Space: "",
Local: key,
},
}
tokens = append(tokens, t, xml.CharData(value), xml.EndElement{Name: t.Name})
}
tokens = append(tokens, xml.EndElement{Name: start.Name})
for _, t := range tokens {
err := e.EncodeToken(t)
if err != nil {
return err
}
}
return e.Flush()
}
func (d *displayXML) Display(entries *LogEntries, fieldNames []string, file *os.File) error {
bytes, err := xml.MarshalIndent(entries, displayPrefix, displayIndentValue)
if err != nil {
return err
}
output := string(bytes)
_, err = fmt.Fprintln(file, output)
return err
}