-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (56 loc) · 1.17 KB
/
Copy pathmain.go
File metadata and controls
70 lines (56 loc) · 1.17 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"strings"
doc "github.com/fochoac/report4go/util"
)
func main() {
var variables = []string{"${fechaCorte}"}
fmt.Println("hola")
xmlFile := getData()
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
var document doc.Document
xml.Unmarshal(byteValue, &document)
for _, P := range *document.Body.P {
row := P.R
for _, cadena := range variables {
var texto *string
if row.T != nil {
texto = row.T
} else {
continue
}
if strings.Contains(*texto, cadena) {
replaceString(texto, cadena)
}
}
}
printDocument(&document)
resultado, err := xml.MarshalIndent(&document, "d", "")
if err != nil {
panic(err)
}
ioutil.WriteFile("salida.xml", resultado, os.ModePerm)
}
func replaceString(source *string, value string) {
replace := strings.Replace(*source, value, "se cambio la vaina", -1)
*source = replace
}
func printDocument(document *doc.Document) {
for _, item := range *document.Body.P {
if item.R.T != nil {
fmt.Println(*item.R.T)
}
}
}
func getData() *os.File {
xmlFile, err := os.Open("document.xml")
if err != nil {
panic(err)
}
return xmlFile
}