diff --git a/public/xml b/public/xml
index 0d8ce2d..e463b37 100644
--- a/public/xml
+++ b/public/xml
@@ -33,7 +33,7 @@ formats with the encoding.xml
package.
encoding.xml
package.
encoding.xml
package.
import (
+ import (
"encoding/xml"
"fmt"
)
@@ -79,7 +77,7 @@ the name of the XML element representing this struct;
type Plant struct {
+ type Plant struct {
XMLName xml.Name `xml:"plant"`
Id int `xml:"id,attr"`
Name string `xml:"name"`
@@ -96,7 +94,7 @@ the name of the XML element representing this struct;
func (p Plant) String() string {
+ func (p Plant) String() string {
return fmt.Sprintf("Plant id=%v, name=%v, origin=%v",
p.Id, p.Name, p.Origin)
}
@@ -111,7 +109,7 @@ the name of the XML element representing this struct;
func main() {
+ func main() {
coffee := &Plant{Id: 27, Name: "Coffee"}
coffee.Origin = []string{"Ethiopia", "Brazil"}
@@ -128,7 +126,7 @@ human-readable output.
out, _ := xml.MarshalIndent(coffee, " ", " ")
+ out, _ := xml.MarshalIndent(coffee, " ", " ")
fmt.Println(string(out))
@@ -143,7 +141,7 @@ it explicitly.
fmt.Println(xml.Header + string(out))
+ fmt.Println(xml.Header + string(out))
var p Plant
+ var p Plant
if err := xml.Unmarshal(out, &p); err != nil {
panic(err)
}
@@ -175,7 +173,7 @@ will be returned.
tomato := &Plant{Id: 81, Name: "Tomato"}
+ tomato := &Plant{Id: 81, Name: "Tomato"}
tomato.Origin = []string{"Mexico", "California"}
@@ -190,7 +188,7 @@ to nest all plant
s under <parent><child>...
- type Nesting struct {
+ type Nesting struct {
XMLName xml.Name `xml:"nesting"`
Plants []*Plant `xml:"parent>child>plant"`
}
@@ -205,7 +203,7 @@ to nest all plant
s under <parent><child>...
- nesting := &Nesting{}
+ nesting := &Nesting{}
nesting.Plants = []*Plant{coffee, tomato}
@@ -218,7 +216,7 @@ to nest all plant
s under <parent><child>...
- out, _ = xml.MarshalIndent(nesting, " ", " ")
+ out, _ = xml.MarshalIndent(nesting, " ", " ")
fmt.Println(string(out))
}
@@ -236,7 +234,7 @@ to nest all plant
s under <parent><child>...
-