// xml doesn't return the standard io.ErrUnexpectedEOF so check for both.
337326
func isUnexpectedEOF(err error) bool {
	if xerr, ok := err.(*xml.SyntaxError); ok {
		return xerr.Msg == "unexpected EOF"
	}
	return err == io.ErrUnexpectedEOF
}
1190932
func (cae *CoordinatesArrayElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(coordinatesStartElement); err != nil {
		return err
	}
	for i, c := range cae.coordinates {
		s := ""
		if i != 0 {
			s = " "
		}
		s += strconv.FormatFloat(c[0], 'f', -1, 64) + "," + strconv.FormatFloat(c[1], 'f', -1, 64)
		if len(c) > 2 && c[2] != 0 {
			s += "," + strconv.FormatFloat(c[2], 'f', -1, 64)
		}
		if err := e.EncodeToken(xml.CharData([]byte(s))); err != nil {
			return err
		}
	}
	return e.EncodeToken(coordinatesEndElement)
}
558394
func (ou *UID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var value string
	err := d.DecodeElement(&value, &start)
	if err != nil {
		return err
	}
	*ou = UID(strings.TrimSpace(value))
	return nil
}
254876
func (r *Response) XML(userStruct interface{}, charsetReader utils.XMLCharDecoder) error {
	if r.Error != nil {
		return r.Error
	}

	xmlDecoder := xml.NewDecoder(r.getInternalReader())
	if charsetReader != nil {
		xmlDecoder.CharsetReader = charsetReader
	}

	defer r.Close()
	if err := xmlDecoder.Decode(&userStruct); err != nil && err != io.EOF {
		return err
	}

	return nil
}
1274502
func (q *Queue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	// Make subtype to avoid recursive UnmarshalXML().
	type queue Queue
	parsedQueue := queue{}
	if err := d.DecodeElement(&parsedQueue, &start); err != nil {
		return err
	}

	if len(parsedQueue.Events) == 0 {
		return errors.New("missing event name(s)")
	}

	eventStringSet := set.NewStringSet()
	for _, eventName := range parsedQueue.Events {
		if eventStringSet.Contains(eventName.String()) {
			return &ErrDuplicateEventName{eventName}
		}

		eventStringSet.Add(eventName.String())
	}

	*q = Queue(parsedQueue)

	return nil
}
727192
func ReadXml(r *http.Request, v interface{}) error {
	body, err := ioutil.ReadAll(r.Body)
	r.Body.Close()
	if err != nil {
		return err
	}
	return xml.Unmarshal(body, v)
}
634763
func (a *Amount) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var value string

	err := d.DecodeElement(&value, &start)
	if err != nil {
		return err
	}

	value = strings.TrimSpace(value)

	// The OFX spec allows the start of the fractional amount to be delineated
	// by a comma, so fix that up before attempting to parse it into big.Rat
	value = strings.Replace(value, ",", ".", 1)

	if _, ok := a.SetString(value); !ok {
		return errors.New("Failed to parse OFX amount")
	}
	return nil
}
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)
}
826797
func (l *InvTranList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	for {
		tok, err := nextNonWhitespaceToken(d)
		if err != nil {
			return err
		} else if end, ok := tok.(xml.EndElement); ok && end.Name.Local == start.Name.Local {
			// If we found the end of our starting element, we're done parsing
			return nil
		} else if startElement, ok := tok.(xml.StartElement); ok {
			switch startElement.Name.Local {
			case "DTSTART":
				var dtstart Date
				if err := d.DecodeElement(&dtstart, &startElement); err != nil {
					return err
				}
				l.DtStart = dtstart
			case "DTEND":
				var dtend Date
				if err := d.DecodeElement(&dtend, &startElement); err != nil {
					return err
				}
				l.DtEnd = dtend
			case "BUYDEBT":
				var tran BuyDebt
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "BUYMF":
				var tran BuyMF
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "BUYOPT":
				var tran BuyOpt
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "BUYOTHER":
				var tran BuyOther
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "BUYSTOCK":
				var tran BuyStock
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "CLOSUREOPT":
				var tran ClosureOpt
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "INCOME":
				var tran Income
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "INVEXPENSE":
				var tran InvExpense
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "JRNLFUND":
				var tran JrnlFund
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "JRNLSEC":
				var tran JrnlSec
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "MARGININTEREST":
				var tran MarginInterest
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "REINVEST":
				var tran Reinvest
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "RETOFCAP":
				var tran RetOfCap
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SELLDEBT":
				var tran SellDebt
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SELLMF":
				var tran SellMF
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SELLOPT":
				var tran SellOpt
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SELLOTHER":
				var tran SellOther
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SELLSTOCK":
				var tran SellStock
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "SPLIT":
				var tran Split
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "TRANSFER":
				var tran Transfer
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.InvTransactions = append(l.InvTransactions, InvTransaction(tran))
			case "INVBANKTRAN":
				var tran InvBankTransaction
				if err := d.DecodeElement(&tran, &startElement); err != nil {
					return err
				}
				l.BankTransactions = append(l.BankTransactions, tran)
			default:
				return errors.New("Invalid INVTRANLIST child tag: " + startElement.Name.Local)
			}
		} else {
			return errors.New("Didn't find an opening element")
		}
	}
}
333181
func ErrUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string) error {
	msg := fmt.Sprintf("Data read ‘%d’ is not equal to the size ‘%d’ of the input Reader.", totalRead, totalSize)
	return ErrorResponse{
		StatusCode: http.StatusBadRequest,
		Code:       "UnexpectedEOF",
		Message:    msg,
		BucketName: bucketName,
		Key:        objectName,
	}
}
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
}
1083033
func (r *Response) ToXML() string{
	bytes, _ := xml.Marshal(r)
	return string(bytes)
}
985388
func (c *CurrSymbol) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(c.String(), start)
}
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
}
596351
func (pipeList *PipeList) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) (err error) {
	content := ""

	if err = decoder.DecodeElement(&content, &start); err != nil {
		return err
	}

	*pipeList = strings.Split(strings.Trim(content, "|"), "|")

	return
}
930105
func (c *Client) ReadXML(v interface{}) (err error) {
	_, r, err := c.NextReader()
	if err != nil {
		return err
	}
	return xml.NewDecoder(r).Decode(v)
}
1283609
func (n *NeptuneApex) parseXML(acc telegraf.Accumulator, data []byte) error {
	r := xmlReply{}
	err := xml.Unmarshal(data, &r)
	if err != nil {
		return fmt.Errorf("unable to unmarshal XML: %v\nXML DATA: %q",
			err, data)
	}

	var reportTime time.Time
	var powerFailed, powerRestored int64
	if reportTime, err = parseTime(r.Date, r.Timezone); err != nil {
		return err
	}
	if val, err := parseTime(r.PowerFailed, r.Timezone); err != nil {
		return err
	} else {
		powerFailed = val.UnixNano()
	}
	if val, err := parseTime(r.PowerRestored, r.Timezone); err != nil {
		return err
	} else {
		powerRestored = val.UnixNano()
	}

	mainFields := map[string]interface{}{
		"serial":         r.Serial,
		"power_failed":   powerFailed,
		"power_restored": powerRestored,
	}
	acc.AddFields(Measurement, mainFields,
		map[string]string{
			"source":   r.Hostname,
			"type":     "controller",
			"software": r.SoftwareVersion,
			"hardware": r.HardwareVersion,
		},
		reportTime)

	// Outlets.
	for _, o := range r.Outlet {
		tags := map[string]string{
			"source":    r.Hostname,
			"output_id": o.OutputID,
			"device_id": o.DeviceID,
			"name":      o.Name,
			"type":      "output",
			"software":  r.SoftwareVersion,
			"hardware":  r.HardwareVersion,
		}
		fields := map[string]interface{}{
			"state": o.State,
		}
		// Find Amp and Watt probes and add them as fields.
		// Remove the redundant probe.
		if pos := findProbe(fmt.Sprintf("%sW", o.Name), r.Probe); pos > -1 {
			value, err := strconv.ParseFloat(
				strings.TrimSpace(r.Probe[pos].Value), 64)
			if err != nil {
				acc.AddError(
					fmt.Errorf(
						"cannot convert string value %q to float64: %v",
						r.Probe[pos].Value, err))
				continue // Skip the whole outlet.
			}
			fields["watt"] = value
			r.Probe[pos] = r.Probe[len(r.Probe)-1]
			r.Probe = r.Probe[:len(r.Probe)-1]
		}
		if pos := findProbe(fmt.Sprintf("%sA", o.Name), r.Probe); pos > -1 {
			value, err := strconv.ParseFloat(
				strings.TrimSpace(r.Probe[pos].Value), 64)
			if err != nil {
				acc.AddError(
					fmt.Errorf(
						"cannot convert string value %q to float64: %v",
						r.Probe[pos].Value, err))
				break // // Skip the whole outlet.
			}
			fields["amp"] = value
			r.Probe[pos] = r.Probe[len(r.Probe)-1]
			r.Probe = r.Probe[:len(r.Probe)-1]
		}
		if o.Xstatus != nil {
			fields["xstatus"] = *o.Xstatus
		}
		// Try to determine outlet type. Focus on accuracy, leaving the
		//outlet_type "unknown" when ambiguous. 24v and vortech cannot be
		// determined.
		switch {
		case strings.HasPrefix(o.DeviceID, "base_Var"):
			tags["output_type"] = "variable"
		case o.DeviceID == "base_Alarm":
			fallthrough
		case o.DeviceID == "base_Warn":
			fallthrough
		case strings.HasPrefix(o.DeviceID, "base_email"):
			tags["output_type"] = "alert"
		case fields["watt"] != nil || fields["amp"] != nil:
			tags["output_type"] = "outlet"
		case strings.HasPrefix(o.DeviceID, "Cntl_"):
			tags["output_type"] = "virtual"
		default:
			tags["output_type"] = "unknown"
		}

		acc.AddFields(Measurement, fields, tags, reportTime)
	}

	// Probes.
	for _, p := range r.Probe {
		value, err := strconv.ParseFloat(strings.TrimSpace(p.Value), 64)
		if err != nil {
			acc.AddError(fmt.Errorf(
				"cannot convert string value %q to float64: %v",
				p.Value, err))
			continue
		}
		fields := map[string]interface{}{
			"value": value,
		}
		tags := map[string]string{
			"source":   r.Hostname,
			"type":     "probe",
			"name":     p.Name,
			"software": r.SoftwareVersion,
			"hardware": r.HardwareVersion,
		}
		if p.Type != nil {
			tags["probe_type"] = *p.Type
		}
		acc.AddFields(Measurement, fields, tags, reportTime)
	}

	return nil
}