goxml/prefix_test.go

45 lines
615 B
Go
Raw Normal View History

2024-11-07 22:48:55 +08:00
package goxml_test
import (
"testing"
"git.pyer.club/kingecg/goxml"
)
type Person struct {
Name string `xml:"p:name"`
Age int `xml:"p:age"`
}
type Employee struct {
Person
Salary int `xml:"p:salary"`
}
func TestUnmarshal(t *testing.T) {
xml := `
<Employee>
<p:name>John Doe</p:name>
<p:age>42</p:age>
<p:salary>100000</p:salary>
</Employee>
`
e := Employee{}
err := goxml.Unmarshal([]byte(xml), &e)
if err != nil {
t.Fatal(err)
}
}
func TestMashal(t *testing.T) {
e := Employee{
Person{
Name: "John",
Age: 30,
},
50000,
}
b, _ := goxml.Marshal(e)
t.Log(string(b))
}