Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
5fde5cd5
Commit
5fde5cd5
authored
Jan 23, 2012
by
Gustavo Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding/xml: support ignoring fields with "-"
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/5564045
parent
fd9c9951
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
src/pkg/encoding/xml/marshal_test.go
src/pkg/encoding/xml/marshal_test.go
+20
-0
src/pkg/encoding/xml/typeinfo.go
src/pkg/encoding/xml/typeinfo.go
+1
-2
No files found.
src/pkg/encoding/xml/marshal_test.go
View file @
5fde5cd5
...
...
@@ -188,6 +188,10 @@ type PresenceTest struct {
Exists
*
struct
{}
}
type
IgnoreTest
struct
{
PublicSecret
string
`xml:"-"`
}
type
MyBytes
[]
byte
type
Data
struct
{
...
...
@@ -592,6 +596,22 @@ var marshalTests = []struct {
},
ExpectXML
:
`<RecurseA><A>a1</A><B><A><A>a2</A></A><B>b1</B></B></RecurseA>`
,
},
// Test ignoring fields via "-" tag
{
ExpectXML
:
`<IgnoreTest></IgnoreTest>`
,
Value
:
&
IgnoreTest
{},
},
{
ExpectXML
:
`<IgnoreTest></IgnoreTest>`
,
Value
:
&
IgnoreTest
{
PublicSecret
:
"can't tell"
},
MarshalOnly
:
true
,
},
{
ExpectXML
:
`<IgnoreTest><PublicSecret>ignore me</PublicSecret></IgnoreTest>`
,
Value
:
&
IgnoreTest
{},
UnmarshalOnly
:
true
,
},
}
func
TestMarshal
(
t
*
testing
.
T
)
{
...
...
src/pkg/encoding/xml/typeinfo.go
View file @
5fde5cd5
...
...
@@ -37,7 +37,6 @@ const (
fAny
// TODO:
//fIgnore
//fOmitEmpty
fMode
=
fElement
|
fAttr
|
fCharData
|
fInnerXml
|
fComment
|
fAny
...
...
@@ -62,7 +61,7 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) {
n
:=
typ
.
NumField
()
for
i
:=
0
;
i
<
n
;
i
++
{
f
:=
typ
.
Field
(
i
)
if
f
.
PkgPath
!=
""
{
if
f
.
PkgPath
!=
""
||
f
.
Tag
.
Get
(
"xml"
)
==
"-"
{
continue
// Private field
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment