// UnmarshalXML deserializes an xml.Decoder into the container v. V
// needs to match the shape of the XML expected to be decoded.
// If the shape doesn't match unmarshaling will fail.
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
}
1287578
func (h *HTMLElement) Unmarshal(v interface{}) error {
	return UnmarshalHTML(v, h.DOM, nil)
}
558688
func (o *OOList) 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 "OOBUYDEBT":
				var oo OOBuyDebt
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOBUYMF":
				var oo OOBuyMF
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOBUYOPT":
				var oo OOBuyOpt
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOBUYOTHER":
				var oo OOBuyOther
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOBUYSTOCK":
				var oo OOBuyStock
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOSELLDEBT":
				var oo OOSellDebt
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOSELLMF":
				var oo OOSellMF
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOSELLOPT":
				var oo OOSellOpt
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOSELLOTHER":
				var oo OOSellOther
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "OOSELLSTOCK":
				var oo OOSellStock
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			case "SWITCHMF":
				var oo OOSwitchMF
				if err := d.DecodeElement(&oo, &startElement); err != nil {
					return err
				}
				*o = append(*o, OpenOrder(oo))
			default:
				return errors.New("Invalid OOList child tag: " + startElement.Name.Local)
			}
		} else {
			return errors.New("Didn't find an opening element")
		}
	}
}
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)
}
403470
func (msl *MessageSetList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	for {
		var msgset MessageSet
		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 _, ok := tok.(xml.StartElement); ok {
			// Found starting tag for <xxxMSGSET>. Get the next one (xxxMSGSETVn) and decode that struct
			tok, err := nextNonWhitespaceToken(d)
			if err != nil {
				return err
			} else if versionStart, ok := tok.(xml.StartElement); ok {
				if err := d.DecodeElement(&msgset, &versionStart); err != nil {
					return err
				}
			} else {
				return errors.New("Invalid MSGSETLIST formatting")
			}
			msgset.Name = msgset.XMLName.Local

			// Eat ending tags for <xxxMSGSET>
			tok, err = nextNonWhitespaceToken(d)
			if err != nil {
				return err
			} else if _, ok := tok.(xml.EndElement); !ok {
				return errors.New("Invalid MSGSETLIST formatting")
			}
		} else {
			return errors.New("MSGSETLIST didn't find an opening xxxMSGSETVn element")
		}
		*msl = MessageSetList(append(*(*[]MessageSet)(msl), msgset))
	}
}
68966
func (k *Kubernetes) UnmarshalTOML(data interface{}) error {
	dataOK, ok := data.(map[string]interface{})
	if !ok {
		return errors.New("bad url for kubernetes input plugin")
	}
	k.URL, _ = dataOK["url"].(string)
	return nil
}
1336749
func (c *DataContainer) UnmarshalJSON(payload []byte) error {
	if bytes.HasPrefix(payload, objectSuffix) {
		return json.Unmarshal(payload, &c.DataObject)
	}

	if bytes.HasPrefix(payload, arraySuffix) {
		return json.Unmarshal(payload, &c.DataArray)
	}

	return errors.New("expected a JSON encoded object or array")
}
44206
func (d *decodeState) unmarshalArray(data Slice, v reflect.Value) {
	// Check for unmarshaler.
	u, ju, ut, pv := d.indirect(v, false)
	if u != nil {
		if err := u.UnmarshalVPack(data); err != nil {
			d.error(err)
		}
		return
	}
	if ju != nil {
		json, err := data.JSONString()
		if err != nil {
			d.error(err)
		} else {
			if err := ju.UnmarshalJSON([]byte(json)); err != nil {
				d.error(err)
			}
		}
		return
	}
	if ut != nil {
		d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type()})
		return
	}

	v = pv

	// Check type of target.
	switch v.Kind() {
	case reflect.Interface:
		if v.NumMethod() == 0 {
			// Decoding into nil interface?  Switch to non-reflect code.
			v.Set(reflect.ValueOf(d.arrayInterface(data)))
			return
		}
		// Otherwise it's invalid.
		fallthrough
	default:
		d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type()})
		return
	case reflect.Array:
	case reflect.Slice:
		break
	}

	i := 0
	it, err := NewArrayIterator(data)
	if err != nil {
		d.error(err)
	}
	for it.IsValid() {
		value, err := it.Value()
		if err != nil {
			d.error(err)
		}

		// Get element of array, growing if necessary.
		if v.Kind() == reflect.Slice {
			// Grow slice if necessary
			if i >= v.Cap() {
				newcap := v.Cap() + v.Cap()/2
				if newcap < 4 {
					newcap = 4
				}
				newv := reflect.MakeSlice(v.Type(), v.Len(), newcap)
				reflect.Copy(newv, v)
				v.Set(newv)
			}
			if i >= v.Len() {
				v.SetLen(i + 1)
			}
		}

		if i < v.Len() {
			// Decode into element.
			d.unmarshalValue(value, v.Index(i))
		}
		i++
		if err := it.Next(); err != nil {
			d.error(err)
		}
	}

	if i < v.Len() {
		if v.Kind() == reflect.Array {
			// Array. Zero the rest.
			z := reflect.Zero(v.Type().Elem())
			for ; i < v.Len(); i++ {
				v.Index(i).Set(z)
			}
		} else {
			v.SetLen(i)
		}
	}
	if i == 0 && v.Kind() == reflect.Slice {
		v.Set(reflect.MakeSlice(v.Type(), 0, 0))
	}
}
1107814
func (cfg *Config) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	for t, err := d.Token(); ; t, err = d.Token() {
		if err != nil {
			if err != io.EOF {
				return err
			}
			return nil
		}

		switch token := t.(type) {
		case xml.StartElement:
			c := &Config{
				parent: cfg,
				Attrs:  make(map[string]string, len(token.Attr)),
			}
			for _, v := range token.Attr {
				c.Attrs[v.Name.Local] = v.Value
			}

			if cfg.Items == nil {
				cfg.Items = make(map[string]*Config)
			}
			if _, found := cfg.Items[token.Name.Local]; found {
				return fmt.Errorf("重复的元素名[%v]", token.Name.Local)
			}
			cfg.Items[token.Name.Local] = c

			cfg = c
		case xml.EndElement:
			if cfg.parent != nil {
				cfg = cfg.parent
			}
		} // end switch
	} // end for
}
1081624
func (p *Procstat) UnmarshalTOML(data interface{}) error {
	dataOK, ok := data.(map[string]interface{})
	if !ok {
		return errors.New("bad exe for procstat input plugin")
	}
	p.Exe, _ = dataOK["exe"].(string)
	return nil
}
1039767
func (od *Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(od.String(), start)
}
860452
func (c *CurrSymbol) 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)

	unit, err := currency.ParseISO(value)
	if err != nil {
		return errors.New("Error parsing CurrSymbol:" + err.Error())
	}
	c.Unit = unit
	return nil
}
317500
func (v *Viper) UnmarshalExact(rawVal interface{}) error {
	config := defaultDecoderConfig(rawVal)
	config.ErrorUnused = true

	err := decode(v.AllSettings(), config)

	if err != nil {
		return err
	}

	return nil
}
1118429
func (input *InputSerialization) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	// Make subtype to avoid recursive UnmarshalXML().
	type subInputSerialization InputSerialization
	parsedInput := subInputSerialization{}
	if err := d.DecodeElement(&parsedInput, &start); err != nil {
		return errMalformedXML(err)
	}

	// If no compression is specified, set to noneType
	if parsedInput.CompressionType == CompressionType("") {
		parsedInput.CompressionType = noneType
	}

	found := 0
	if !parsedInput.CSVArgs.IsEmpty() {
		parsedInput.format = csvFormat
		found++
	}
	if !parsedInput.JSONArgs.IsEmpty() {
		parsedInput.format = jsonFormat
		found++
	}
	if !parsedInput.ParquetArgs.IsEmpty() {
		if parsedInput.CompressionType != "" && parsedInput.CompressionType != noneType {
			return errInvalidRequestParameter(fmt.Errorf("CompressionType must be NONE for Parquet format"))
		}

		parsedInput.format = parquetFormat
		found++
	}

	if found != 1 {
		return errInvalidDataSource(nil)
	}

	*input = InputSerialization(parsedInput)
	input.unmarshaled = true
	return nil
}
1187918
func (ft *Filetime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	type time struct {
		Low  string `xml:"LOWPART"`
		High string `xml:"HIGHPART"`
	}
	var t time
	err := d.DecodeElement(&t, &start)
	if err != nil {
		return err
	}

	low, err := strconv.ParseUint(t.Low, 0, 32)
	if err != nil {
		return err
	}
	high, err := strconv.ParseUint(t.High, 0, 32)
	if err != nil {
		return err
	}

	ft.LowDateTime = uint32(low)
	ft.HighDateTime = uint32(high)
	return nil
}
1197740
func (n *Nginx) UnmarshalTOML(data interface{}) error {
	dataOK, ok := data.(map[string]interface{})
	if !ok {
		return errors.New("bad urls for nginx input plugin")
	}
	urls, ok := dataOK["urls"].([]interface{})
	if !ok {
		return errors.New("urls is not an array for nginx input plugin")
	}
	for _, url := range urls {
		n.URLs = append(n.URLs, url.(string))
	}
	return nil
}
717279
func (name Name) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(name.String(), start)
}