mirror of
https://github.com/golang/go
synced 2024-11-20 02:54:39 -07:00
The Go programming language
1627b46eaa
This CL improves the xml package in the following ways: - makes its interface match established conventions - brings Marshal and Unmarshal closer together - fixes a large number of bugs and adds tests - improves speed significantly - organizes and simplifies the code Fixes #2426. Fixes #2406. Fixes #1989. What follows is a detailed list of those changes. - All matching is case sensitive without special processing to the field name or xml tag in an attempt to match them. Customize the field tag as desired to match the correct XML elements. - Flags are ",flag" rather than "flag". The names "attr", "chardata", etc, may be used to name actual XML elements. - Overriding of attribute names is possible with "name,attr". - Attribute fields are marshalled properly if they have non-string types. Previously they were unmarshalled, but were ignored at marshalling time. - Comment fields tagged with ",comment" are marshalled properly, rather than being marshalled as normal fields. - The handling of the Any field has been replaced by the ",any" flag to avoid unexpected results when using the field name for other purposes, and has also been fixed to interact properly with name paths. Previously the feature would not function if any field in the type had a name path in its tag. - Embedded struct support fixed and cleaned so it works when marshalling and also when using field paths deeper than one level. - Conflict reporting on field names have been expanded to cover all fields. Previously it'd catch only conflicts of paths deeper than one level. Also interacts correctly with embedded structs now. - A trailing '>' is disallowed in xml tags. It used to be supported for removing the ambiguity between "attr" and "attr>", but the marshalling support for that was broken, and it's now unnecessary. Use "name" instead of "name>". - Fixed docs to point out that a XMLName doesn't have to be an xml.Name (e.g. a struct{} is a good fit too). The code was already working like that. - Fixed asymmetry in the precedence of XML element names between marshalling and unmarshalling. Marshal would consider the XMLName of the field type before the field tag, while unmarshalling would do the opposite. Now both respect the tag of the XMLName field first, and a nice error message is provided in case an attempt is made to name a field with its tag in a way that would conflict with the underlying type's XMLName field. - Do not marshal broken "<???>" tags when in doubt. Use the type name, and error out if that's not possible. - Do not break down unmarshalling if there's an interface{} field in a struct. - Significant speed boost due to caching of type metadata and overall allocation clean ups. The following timings reflect processing of the the atom test data: Old: BenchmarkMarshal 50000 48798 ns/op BenchmarkUnmarshal 5000 357174 ns/op New: BenchmarkMarshal 100000 19799 ns/op BenchmarkUnmarshal 10000 128525 ns/op R=cw, gustavo, kevlar, adg, rogpeppe, fullung, christoph, rsc CC=golang-dev https://golang.org/cl/5503078 |
||
---|---|---|
doc | ||
include | ||
lib | ||
misc | ||
src | ||
test | ||
.hgignore | ||
.hgtags | ||
AUTHORS | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README | ||
robots.txt |
This is the source code repository for the Go programming language. For documentation about how to install and use Go, visit http://golang.org/ or load doc/install.html in your web browser. After installing Go, you can view a nicely formatted doc/install.html by running godoc --http=:6060 and then visiting http://localhost:6060/doc/install.html. Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file. -- Binary Distribution Notes If you have just untarred a binary Go distribution, you need to set the environment variable $GOROOT to the full path of the go directory (the one containing this README). You can omit the variable if you unpack it into /usr/local/go, or if you rebuild from sources by running all.bash (see doc/install.html). You should also add the Go binary directory $GOROOT/bin to your shell's path. For example, if you extracted the tar file into $HOME/go, you might put the following in your .profile: export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin See doc/install.html for more details.