Add lss2md utility
This commit is contained in:
parent
a5b24b7919
commit
483e0a7fe7
1 changed files with 57 additions and 0 deletions
57
misc/lss2md/main.go
Normal file
57
misc/lss2md/main.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Questionnaire struct {
|
||||||
|
XMLName xml.Name `xml:"questionnaire"`
|
||||||
|
Section []struct {
|
||||||
|
Question []struct {
|
||||||
|
Text string `xml:"text"`
|
||||||
|
Response struct {
|
||||||
|
Fixed struct {
|
||||||
|
Category []struct {
|
||||||
|
Label string `xml:"label"`
|
||||||
|
} `xml:"category"`
|
||||||
|
} `xml:"fixed"`
|
||||||
|
} `xml:"response"`
|
||||||
|
} `xml:"question"`
|
||||||
|
} `xml:"section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if len(flag.Args()) == 0 {
|
||||||
|
panic("A filename should be provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFile, err := os.Open(flag.Arg(0))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer xmlFile.Close()
|
||||||
|
|
||||||
|
byteValue, _ := ioutil.ReadAll(xmlFile)
|
||||||
|
|
||||||
|
var questionnaire Questionnaire
|
||||||
|
xml.Unmarshal(byteValue, &questionnaire)
|
||||||
|
|
||||||
|
for i, section := range questionnaire.Section {
|
||||||
|
for j, question := range section.Question {
|
||||||
|
mdContent := question.Text + "\n\n"
|
||||||
|
for _, answer := range question.Response.Fixed.Category {
|
||||||
|
mdContent += "* " + answer.Label + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
mdFileName := fmt.Sprintf("question_%d_%d.md", i+1, j+1)
|
||||||
|
ioutil.WriteFile(mdFileName, []byte(mdContent), 0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue