Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/XML-Output/Go/xml-output-1.go
Normal file
35
Task/XML-Output/Go/xml-output-1.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Function required by task description.
|
||||
func xRemarks(r CharacterRemarks) (string, error) {
|
||||
b, err := xml.MarshalIndent(r, "", " ")
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// Task description allows the function to take "a single mapping..."
|
||||
// This data structure represents a mapping.
|
||||
type CharacterRemarks struct {
|
||||
Character []crm
|
||||
}
|
||||
|
||||
type crm struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Remark string `xml:",chardata"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
x, err := xRemarks(CharacterRemarks{[]crm{
|
||||
{`April`, `Bubbly: I'm > Tam and <= Emily`},
|
||||
{`Tam O'Shanter`, `Burns: "When chapman billies leave the street ..."`},
|
||||
{`Emily`, `Short & shrift`},
|
||||
}})
|
||||
if err != nil {
|
||||
x = err.Error()
|
||||
}
|
||||
fmt.Println(x)
|
||||
}
|
||||
5
Task/XML-Output/Go/xml-output-2.go
Normal file
5
Task/XML-Output/Go/xml-output-2.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<CharacterRemarks>
|
||||
<Character name="April">Bubbly: I'm > Tam and <= Emily</Character>
|
||||
<Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
|
||||
<Character name="Emily">Short & shrift</Character>
|
||||
</CharacterRemarks>
|
||||
46
Task/XML-Output/Go/xml-output-3.go
Normal file
46
Task/XML-Output/Go/xml-output-3.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type crm struct {
|
||||
Char, Rem string
|
||||
}
|
||||
|
||||
var tmpl = `<CharacterRemarks>
|
||||
{{range .}} <Character name="{{xml .Char}}">{{xml .Rem}}</Character>
|
||||
{{end}}</CharacterRemarks>
|
||||
`
|
||||
|
||||
func xmlEscapeString(s string) string {
|
||||
var b strings.Builder
|
||||
xml.Escape(&b, []byte(s))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func main() {
|
||||
xt := template.New("").Funcs(template.FuncMap{"xml": xmlEscapeString})
|
||||
template.Must(xt.Parse(tmpl))
|
||||
|
||||
// Define function required by task description.
|
||||
xRemarks := func(crms []crm) (string, error) {
|
||||
var b strings.Builder
|
||||
err := xt.Execute(&b, crms)
|
||||
return b.String(), err
|
||||
}
|
||||
|
||||
// Call the function with example data. The data is represented as
|
||||
// a "single mapping" as allowed by the task, rather than two lists.
|
||||
x, err := xRemarks([]crm{
|
||||
{`April`, `Bubbly: I'm > Tam and <= Emily`},
|
||||
{`Tam O'Shanter`, `Burns: "When chapman billies leave the street ..."`},
|
||||
{`Emily`, `Short & shrift`}})
|
||||
if err != nil {
|
||||
x = err.Error()
|
||||
}
|
||||
fmt.Println(x)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue