Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: doc example is wrong #2831

Closed
gopherbot opened this Issue Feb 2, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@gopherbot
Copy link

gopherbot commented Feb 2, 2012

by abdul.h.chaudhry:

I tried to create a simple example based on the documentation 
godoc encoding/xml Unmarshal

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
osx

Which revision are you using?  (hg identify)
1107a7d3cb07 weekly/weekly.2012-01-27


I tried this test case and it fails with the error EOF

:-

package main

import (
  "testing"
  "encoding/xml"
)

type Email struct {
  Where string `xml:",attr"`
  Addr  string
}

type Result struct {
  Email []Email
}

func Test_Update_2(t *testing.T) {
  result := new(Result)
  body := "<result> <email where='home'> <addr>gre@example.com</addr> </email>"
  err := xml.Unmarshal([]byte(body), &result)
  if err != nil {
    t.Error("xml.UnMarshal:", err)
  }
  t.Log("result:", result)
}
@gopherbot

This comment has been minimized.

Copy link
Author

gopherbot commented Feb 2, 2012

Comment 1 by abdul.h.chaudhry:

the EOF is caused by the lack of result but the unmarshal still seems broken. The logs
indicates unmarshal didnt do anything
func Test_Update_2(t *testing.T) {
  result := new(Result)
  body := "<result> <email where='home'> <addr>gre@example.com</addr> </email></result>"
  err := xml.Unmarshal([]byte(body), &result)
  if err != nil {
    t.Error("xml.UnMarshal:", err)
  }
  t.Error("result:", result)
}
--- FAIL: main.Test_Update_2 (0.00 seconds)
    y.go:981: result: &{[]}
FAIL
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Feb 2, 2012

Comment 2:

The xml input/output in the example needs to use capitalized
<> tags, like <Where>.
Russ

Labels changed: added priority-go1, removed priority-triage.

Owner changed to builder@golang.org.

Status changed to Accepted.

@niemeyer

This comment has been minimized.

Copy link
Contributor

niemeyer commented Feb 23, 2012

Comment 3:

This issue was closed by revision 133c6bf.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015

@rsc rsc removed the priority-go1 label Apr 10, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.