Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created August 10, 2011 07:05
Show Gist options
  • Save bemasher/1136281 to your computer and use it in GitHub Desktop.
Save bemasher/1136281 to your computer and use it in GitHub Desktop.
Go is the better structured and long-winded version. Python is the simpler and much more trouble-prone.
<Person>
<Name>Doug</Name>
<Age>23</Age>
<YChromosone>true</YChromosone>
</Person>
<Person>
<Name>Doug</Name>
<Age>23</Age>
<YChromosone>True</YChromosone>
</Person>
package main
import (
"os"
"fmt"
"xml"
)
type Person struct {
XMLName xml.Name `xml:"Person"`
Name string
Age int
YChromosone bool
}
func main() {
doug := Person{Name:"Doug", Age:23, YChromosone:true}
xml.Marshal(os.Stdout, doug)
}
from lxml import etree
from lxml.builder import E
xml = E.Person(
E.Name("Doug"),
E.Age("23"),
E.YChromosone("True")
)
print etree.tostring(xml, pretty_print=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment