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.

- + @@ -42,10 +42,8 @@ formats with the encoding.xml package.

- - - -
package main
+            
+          
package main
 
@@ -57,7 +55,7 @@ formats with the 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))
 
@@ -159,7 +157,7 @@ will be returned.

-
    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 plants 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 plants under <parent><child>...
           
             
-            
    nesting := &Nesting{}
+          
    nesting := &Nesting{}
     nesting.Plants = []*Plant{coffee, tomato}
 
@@ -218,7 +216,7 @@ to nest all plants under <parent><child>... -
    out, _ = xml.MarshalIndent(nesting, " ", "  ")
+          
    out, _ = xml.MarshalIndent(nesting, " ", "  ")
     fmt.Println(string(out))
 }
 
@@ -236,7 +234,7 @@ to nest all plants under <parent><child>... -
$ go run xml.go
+          
$ go run xml.go
  <plant id="27">
    <name>Coffee</name>
    <origin>Ethiopia</origin>
@@ -281,5 +279,10 @@ to nest all plants under <parent><child>...Mark McGranaghan | source | license
       

+ +