Golang encoding/xml.Name type examples

package encoding/xml

A Name represents an XML name (Local) annotated with a name space identifier (Space). In tokens returned by Decoder.Token, the Space identifier is given as a canonical URL, not the short prefix used in the document being parsed.

Golang encoding/xml.Name type usage examples

Example 1:

 type ExternalIPAddress struct {
  XMLName xml.Name `xml:"NewExternalIPAddress"`
  IP string
 }

Example 2:

 ...
 bodyBuf := bytes.NewBuffer(nil)
 enc := xml.NewEncoder(bodyBuf)
 start := xml.StartElement{
  Name: xml.Name{
  Space: "",
  Local: reflect.Indirect(reflect.ValueOf(req)).Type().Name(),
  },
  Attr: []xml.Attr{{xml.Name{"", "xmlns"}, "http://localhost/xmldoc/2014-08-01/"}},
 }
 ...

Reference :

http://golang.org/pkg/encoding/xml/#Name

Advertisement