XML/Output: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Go}}: update for new template library, also added an error check) |
||
Line 617: | Line 617: | ||
import ( |
import ( |
||
" |
"bytes" |
||
"fmt" |
|||
"os" |
"os" |
||
"template" |
"template" |
||
Line 633: | Line 634: | ||
var tmpl = `<CharacterRemarks> |
var tmpl = `<CharacterRemarks> |
||
⚫ | |||
{.repeated section @} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
` |
` |
||
func |
func xmlEscapeString(s string) string { |
||
var b bytes.Buffer |
|||
xml.Escape( |
xml.Escape(&b, []byte(s)) |
||
return b.String() |
|||
} |
} |
||
func main() { |
func main() { |
||
xt := template. |
xt := template.New("").Funcs(template.FuncMap{"xml": xmlEscapeString}) |
||
template.Must(xt.Parse(tmpl)) |
|||
if err := xt.Execute(os.Stdout, crms); err != nil { |
|||
fmt.Println(err) |
|||
⚫ | |||
}</lang> |
}</lang> |
||
Output: |
Output: |