Created
September 7, 2012 18:19
-
-
Save angeldm/3668328 to your computer and use it in GitHub Desktop.
Marshal
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
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
) | |
type DIDLLite struct { | |
XMLName xml.Name | |
DC string `xml:"xmlns:dc,attr"` | |
UPNP string `xml:"xmlns:upnp,attr"` | |
XSI string `xml:"xmlns:xsi,attr"` | |
XLOC string `xml:"xsi:schemaLocation,attr"` | |
Objects []Object `xml:"item"` | |
} | |
type Object struct { | |
ID string `xml:"id,attr"` | |
Parent string `xml:"parentID,attr"` | |
Restricted string `xml:"restricted,attr"` | |
} | |
func main() { | |
d := DIDLLite{ | |
XMLName: xml.Name{ | |
Space: "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/", | |
Local: "DIDL-Lite", | |
}, | |
DC: "http://purl.org/dc/elements/1.1/", | |
UPNP: "urn:schemas-upnp-org:metadata-1-0/upnp/", | |
XSI: "http://www.w3.org/2001/XMLSchema-instance", | |
XLOC: ` | |
urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ | |
http://www.upnp.org/schemas/av/didl-lite-v2-20060531.xsd | |
urn:schemas-upnp-org:metadata-1-0/upnp/ | |
http://www.upnp.org/schemas/av/upnp-v2-20061231.xsd`, | |
Objects: []Object{{ID: "18", Parent: "13", Restricted: "0"}}, | |
} | |
b, err := xml.MarshalIndent(d, "", " ") | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println(string(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment