-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example #7: marshaling to XML with indentation
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
) | ||
|
||
type User1 struct { | ||
XMLName xml.Name `xml:"user"` | ||
id uint32 `xml:"id"` | ||
name string `xml:"user_name"` | ||
surname string `xml:"surname"` | ||
} | ||
|
||
type User2 struct { | ||
XMLName xml.Name `xml:"user"` | ||
Id uint32 `xml:"id"` | ||
Name string `xml:"user_name"` | ||
Surname string `xml:"surname"` | ||
} | ||
|
||
func main() { | ||
user1 := User1{ | ||
id: 1, | ||
name: "Pepek", | ||
surname: "Vyskoč"} | ||
|
||
user2 := User2{ | ||
Id: 1, | ||
Name: "Pepek", | ||
Surname: "Vyskoč"} | ||
|
||
user1asXML, _ := xml.MarshalIndent(user1, "", " ") | ||
fmt.Println(string(user1asXML)) | ||
|
||
fmt.Println() | ||
|
||
user2asXML, _ := xml.MarshalIndent(user2, "", " ") | ||
fmt.Println(string(user2asXML)) | ||
|
||
fmt.Println() | ||
|
||
user2asXML, _ = xml.MarshalIndent(user2, "", "\t") | ||
fmt.Println(string(user2asXML)) | ||
|
||
fmt.Println() | ||
|
||
user2asXML, _ = xml.MarshalIndent(user2, "\t", "\t") | ||
fmt.Println(string(user2asXML)) | ||
} |