// XML marshals the given interface object and writes the XML response to the client.
496492
func (ctx *context) XML(v interface{}, opts ...XML) (int, error) {
	options := DefaultXMLOptions

	if len(opts) > 0 {
		options = opts[0]
	}

	ctx.ContentType(ContentXMLHeaderValue)

	n, err := WriteXML(ctx.writer, v, options)
	if err != nil {
		ctx.StatusCode(http.StatusInternalServerError)
		return 0, err
	}

	return n, err
}
1053772
func (ctx *Context) ServeXML(obj interface{}) error {
	encoder := xml.NewEncoder(ctx)
	ctx.Header().Set("Content-Type", "application/xml; charset=UTF-8")
	err := encoder.Encode(obj)
	if err != nil {
		ctx.Header().Del("Content-Type")
	}
	return err
}
825381
func XMLHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/xml")
	fmt.Fprint(w, xmlData)
}
627377
func (e Env) Marshal() (string, error) {
	x, err := xml.Marshal(e)
	if err != nil {
		return "", err
	}

	return fmt.Sprintf("%s%s", xml.Header, x), nil
}
1269400
func Marshal(object interface{}) (data string, err error) {
	if t, err := json.Marshal(object); err != nil {
		data = ""
	} else {
		data = string(t)
	}
	return
}
951847
func XMLRender(status int, indent bool, data interface{}, prefix []byte) *XML {
	return &XML{
		Indent: indent,
		Prefix: prefix,
		Data:   data,
		Head: &Head{
			Status:  status,
			Content: ContentXML,
		},
	}
}
1046037
func (m EntityDescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	type Alias EntityDescriptor
	aux := &struct {
		ValidUntil    RelaxedTime `xml:"validUntil,attr,omitempty"`
		CacheDuration Duration    `xml:"cacheDuration,attr,omitempty"`
		*Alias
	}{
		ValidUntil:    RelaxedTime(m.ValidUntil),
		CacheDuration: Duration(m.CacheDuration),
		Alias:         (*Alias)(&m),
	}
	return e.Encode(aux)
}
344305
func (r *Request) Marshal() ([]byte, error) {
	ctx := make(map[string]interface{})
	if r.Ctx != nil {
		r.Ctx.ForEach(func(k string, v interface{}) interface{} {
			ctx[k] = v
			return nil
		})
	}
	var err error
	var body []byte
	if r.Body != nil {
		body, err = ioutil.ReadAll(r.Body)
		if err != nil {
			return nil, err
		}
	}
	sr := &serializableRequest{
		URL:    r.URL.String(),
		Method: r.Method,
		Body:   body,
		ID:     r.ID,
		Ctx:    ctx,
	}
	if r.Headers != nil {
		sr.Headers = *r.Headers
	}
	return json.Marshal(sr)
}
350204
func (c *Consumer) PostXML(url string, body string, token *AccessToken) (resp *http.Response, err error) {
	return c.makeAuthorizedRequest("POST", url, LOC_XML, body, nil, token)
}
994470
func (c *Conditions) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	type Alias Conditions
	aux := &struct {
		NotBefore    RelaxedTime `xml:",attr"`
		NotOnOrAfter RelaxedTime `xml:",attr"`
		*Alias
	}{
		NotBefore:    RelaxedTime(c.NotBefore),
		NotOnOrAfter: RelaxedTime(c.NotOnOrAfter),
		Alias:        (*Alias)(c),
	}
	return e.EncodeElement(aux, start)
}
499284
func (c *Ctx) XMLBytes(code int, b []byte) (err error) {

	c.response.Header().Set(ContentType, ApplicationXMLCharsetUTF8)
	c.response.WriteHeader(code)

	if _, err = c.response.Write([]byte(xml.Header)); err == nil {
		_, err = c.response.Write(b)
	}

	return
}
948520
func (c *Controller) RenderXML(o interface{}) Result {
	c.setStatusIfNil(http.StatusOK)

	return RenderXMLResult{o}
}
1105938
func Marshal(input interface{}) (string, error) {
	jsonBytes, err := json.Marshal(input)
	if err != nil {
		return "", err
	}
	xmlBytes, err := EncodeJSONBytes(jsonBytes)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%s%s%s%s", XMLHeader, Header, string(xmlBytes), Footer), nil
}
699532
func (se *SimpleElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(xml.CharData(se.value), se.StartElement)
}
332986
func (d *Databook) XML() (*Exportable, error) {
	b := newBuffer()
	b.WriteString("<databook>\n")
	for _, s := range d.sheets {
		b.WriteString("  <sheet>\n    <title>" + s.title + "</title>\n    ")
		row, err := s.dataset.XMLWithTagNamePrefixIndent("row", "      ", "  ")
		if err != nil {
			return nil, err
		}
		b.Write(row.Bytes())
		b.WriteString("\n  </sheet>")
	}
	b.WriteString("\n</databook>")
	return newExportable(b), nil
}
220310
func (p *PositionList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	invPosListElement := xml.StartElement{Name: xml.Name{Local: "INVPOSLIST"}}
	if err := e.EncodeToken(invPosListElement); err != nil {
		return err
	}
	for _, position := range *p {
		start := xml.StartElement{Name: xml.Name{Local: position.PositionType()}}
		switch pos := position.(type) {
		case DebtPosition:
			if err := e.EncodeElement(&pos, start); err != nil {
				return err
			}
		case MFPosition:
			if err := e.EncodeElement(&pos, start); err != nil {
				return err
			}
		case OptPosition:
			if err := e.EncodeElement(&pos, start); err != nil {
				return err
			}
		case OtherPosition:
			if err := e.EncodeElement(&pos, start); err != nil {
				return err
			}
		case StockPosition:
			if err := e.EncodeElement(&pos, start); err != nil {
				return err
			}
		default:
			return errors.New("Invalid INVPOSLIST child type: " + pos.PositionType())
		}
	}
	if err := e.EncodeToken(invPosListElement.End()); err != nil {
		return err
	}
	return nil
}
1348033
func (r *Render) XML(w io.Writer, status int, v interface{}) error {
	head := Head{
		ContentType: r.opt.XMLContentType + r.compiledCharset,
		Status:      status,
	}

	x := XML{
		Head:   head,
		Indent: r.opt.IndentXML,
		Prefix: r.opt.PrefixXML,
	}

	return r.Render(w, x, v)
}