// XML marshals provided interface + returns XML + status code
347293
func (c *Ctx) XML(code int, i interface{}) error {

	b, err := xml.Marshal(i)
	if err != nil {
		return err
	}

	return c.XMLBytes(code, b)
}
213339
func (su *sitemapURL) XML() []byte {
	doc := etree.NewDocument()
	url := doc.CreateElement("url")

	SetBuilderElementValue(url, su.data.URLJoinBy("loc", "host", "loc"), "loc")
	if _, ok := SetBuilderElementValue(url, su.data, "lastmod"); !ok {
		lastmod := url.CreateElement("lastmod")
		lastmod.SetText(time.Now().Format(time.RFC3339))
	}
	if _, ok := SetBuilderElementValue(url, su.data, "changefreq"); !ok {
		changefreq := url.CreateElement("changefreq")
		changefreq.SetText("weekly")
	}
	if _, ok := SetBuilderElementValue(url, su.data, "priority"); !ok {
		priority := url.CreateElement("priority")
		priority.SetText("0.5")
	}
	SetBuilderElementValue(url, su.data, "expires")
	SetBuilderElementValue(url, su.data, "mobile")
	SetBuilderElementValue(url, su.data, "news")
	SetBuilderElementValue(url, su.data, "video")
	SetBuilderElementValue(url, su.data, "image")
	SetBuilderElementValue(url, su.data, "geo")

	if su.opts.pretty {
		doc.Indent(2)
	}
	buf := poolBuffer.Get()
	doc.WriteTo(buf)

	bytes := buf.Bytes()
	poolBuffer.Put(buf)

	return bytes
}
1309076
func marshal(i interface{}) (string, []byte, error) {
	if _, ok := i.(proto.Message); ok {
		data, err := marshalPB(i)
		return contentTypePB, data, err
	}
	data, err := json.Marshal(i)
	return contentTypeJSON, data, err
}
494575
func (c *Context) XML(code int, data interface{}) (err error) {
	c.response.Header().Set("Content-Type", "application/xml; charset=utf-8")
	c.response.WriteHeader(code)
	if !c.response.done {
		c.response.Write([]byte(xml.Header))
	}
	if data != nil {
		xml.NewEncoder(c.response).Encode(data)
	}
	return
}
1270944
func Xml(v interface{}, rootTag ...string) ([]byte, error) {
	if reflect.TypeOf(v).Kind() == reflect.Struct {
		return xml.Marshal(v)
	}

	var err error
	s := new(string)
	p := new(pretty)

	var rt string
	if len(rootTag) == 1 {
		rt = rootTag[0]
	} else {
		rt = DefaultRootTag
	}

	var ss string
	var b []byte
	switch v.(type) {
	case []interface{}:
		ss = "<" + rt + ">"
		for _, vv := range v.([]interface{}) {
			switch vv.(type) {
			case map[string]interface{}:
				m := vv.(map[string]interface{})
				if len(m) == 1 {
					for tag, val := range m {
						err = mapToXmlIndent(false, s, tag, val, p)
					}
				} else {
					err = mapToXmlIndent(false, s, "element", vv, p)
				}
			default:
				err = mapToXmlIndent(false, s, "element", vv, p)
			}
			if err != nil {
				break
			}
		}
		ss += *s + "</" + rt + ">"
		b = []byte(ss)
	case map[string]interface{}:
		b, err = anyxml(v.(map[string]interface{}), rootTag...)
	case []map[string]interface{}:
		for _, vv := range v.([]map[string]interface{}) {
			b, err = anyxml(vv, rootTag...)
			ss += string(b)
			if err != nil {
				break
			}
		}
		b = []byte(ss)
	default:
		err = mapToXmlIndent(false, s, rt, v, p)
		b = []byte(*s)
	}

	return b, err
}
699532
func (se *SimpleElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(xml.CharData(se.value), se.StartElement)
}
1345229
func (f *Formatter) Marshal(v interface{}) ([]byte, error) {
	data, err := json.Marshal(v)
	if err != nil {
		return nil, err
	}

	return f.Format(data)
}
985388
func (c *CurrSymbol) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(c.String(), start)
}
934872
func (ce *CompoundElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(ce.StartElement); err != nil {
		return err
	}
	for _, c := range ce.children {
		if err := e.EncodeElement(c, ce.StartElement); err != nil {
			return err
		}
	}
	return e.EncodeToken(ce.End())
}
825381
func XMLHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/xml")
	fmt.Fprint(w, xmlData)
}
1329918
func (o *Object) Marshal(attributes interface{}) *Error {
	raw, err := json.MarshalIndent(attributes, "", " ")
	if err != nil {
		return ISE(fmt.Sprintf("Error marshaling attrs while creating a new JSON Object: %s", err))
	}

	o.Attributes = raw
	return nil
}
126385
func (or *Response) Marshal() (*bytes.Buffer, error) {
	var b bytes.Buffer

	// Write the header appropriate to our version
	writeHeader(&b, or.Version)

	encoder := xml.NewEncoder(&b)
	encoder.Indent("", "    ")

	ofxElement := xml.StartElement{Name: xml.Name{Local: "OFX"}}

	if err := encoder.EncodeToken(ofxElement); err != nil {
		return nil, err
	}

	if ok, err := or.Signon.Valid(or.Version); !ok {
		return nil, err
	}
	signonMsgSet := xml.StartElement{Name: xml.Name{Local: SignonRs.String()}}
	if err := encoder.EncodeToken(signonMsgSet); err != nil {
		return nil, err
	}
	if err := encoder.Encode(&or.Signon); err != nil {
		return nil, err
	}
	if err := encoder.EncodeToken(signonMsgSet.End()); err != nil {
		return nil, err
	}

	messageSets := []struct {
		Messages []Message
		Type     messageType
	}{
		{or.Signup, SignupRs},
		{or.Bank, BankRs},
		{or.CreditCard, CreditCardRs},
		{or.Loan, LoanRs},
		{or.InvStmt, InvStmtRs},
		{or.InterXfer, InterXferRs},
		{or.WireXfer, WireXferRs},
		{or.Billpay, BillpayRs},
		{or.Email, EmailRs},
		{or.SecList, SecListRs},
		{or.PresDir, PresDirRs},
		{or.PresDlv, PresDlvRs},
		{or.Prof, ProfRs},
		{or.Image, ImageRs},
	}
	for _, set := range messageSets {
		if err := encodeMessageSet(encoder, set.Messages, set.Type, or.Version); err != nil {
			return nil, err
		}
	}

	if err := encoder.EncodeToken(ofxElement.End()); err != nil {
		return nil, err
	}

	if err := encoder.Flush(); err != nil {
		return nil, err
	}
	return &b, nil
}
1131649
func (r *SecurityList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	secListElement := xml.StartElement{Name: xml.Name{Local: "SECLIST"}}
	if err := e.EncodeToken(secListElement); err != nil {
		return err
	}
	for _, s := range r.Securities {
		start := xml.StartElement{Name: xml.Name{Local: s.SecurityType()}}
		switch sec := s.(type) {
		case DebtInfo:
			if err := e.EncodeElement(&sec, start); err != nil {
				return err
			}
		case MFInfo:
			if err := e.EncodeElement(&sec, start); err != nil {
				return err
			}
		case OptInfo:
			if err := e.EncodeElement(&sec, start); err != nil {
				return err
			}
		case OtherInfo:
			if err := e.EncodeElement(&sec, start); err != nil {
				return err
			}
		case StockInfo:
			if err := e.EncodeElement(&sec, start); err != nil {
				return err
			}
		default:
			return errors.New("Invalid SECLIST child type: " + sec.SecurityType())
		}
	}
	if err := e.EncodeToken(secListElement.End()); err != nil {
		return err
	}
	return nil
}
161082
func UnmarshalXML(v interface{}, d *xml.Decoder, wrapper string) error {
	n, err := XMLToStruct(d, nil)
	if err != nil {
		return err
	}
	if n.Children != nil {
		for _, root := range n.Children {
			for _, c := range root {
				if wrappedChild, ok := c.Children[wrapper]; ok {
					c = wrappedChild[0] // pull out wrapped element
				}

				err = parse(reflect.ValueOf(v), c, "")
				if err != nil {
					if err == io.EOF {
						return nil
					}
					return err
				}
			}
		}
		return nil
	}
	return nil
}
77841
func (r *Response) WriteHeaderAndXml(status int, value interface{}) error {
	return writeXML(r, status, MIME_XML, value)
}
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)
}
481273
func (ce *CoordinatesElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(coordinatesStartElement); err != nil {
		return err
	}
	for i, c := range ce.coordinates {
		s := ""
		if i != 0 {
			s = " "
		}
		s += strconv.FormatFloat(c.Lon, 'f', -1, 64) + "," + strconv.FormatFloat(c.Lat, 'f', -1, 64)
		if c.Alt != 0 {
			s += "," + strconv.FormatFloat(c.Alt, 'f', -1, 64)
		}
		if err := e.EncodeToken(xml.CharData([]byte(s))); err != nil {
			return err
		}
	}
	return e.EncodeToken(coordinatesEndElement)
}