How can I save a xml file but the data will be coming from a Input Field?

I try using this code I found in Youtube but I want to get the text/data from a input field, Can anyone please help me?
public string information is the real code but I try to modify it and change it to public InputField information and it gives me this error -

InvalidOperationException: To be XML serializable, types which inherit from
IEnumerable must have an
implementation of Add(System.Object)
at all levels of their inheritance
hierarchy. UnityEngine.Transform does
not implement Add(System.Object).

public class XMLManager : MonoBehaviour 
	public static XMLManager ins;

	void Awake(){
		ins = this;

	public ItemDatabase itemDB;

	public void SaveItems(){
		XmlSerializer serializer = new XmlSerializer (typeof(ItemDatabase));
		FileStream stream = new FileStream (Application.dataPath + "/XML File/sample.xml", FileMode.Create);
		serializer.Serialize (stream, itemDB);
		stream.Close ();
public class ItemEntry{
        public InputField information

public class ItemDatabase{
	public List<ItemEntry> list = new List<ItemEntry> ();

The issue most likely comes from the list of ItemEntry in ItemDatabase.

This is a list of wrapped InputField which is a MonoBehaviour component and contains a reference to Transform. This is possibly the reason of the error you are showing. Fact is, I’d say more errors are coming but the compiler stopped there.

The solution would be to discard the serialization of InputField but only of string-

 public class ItemDatabase{
     public List<string> list = new List<string> ();
     public ItemDatabase(){}
     public void SetValues(IEnumerable<InputField> ifs){
            this.list = new List<string>();
            if(ifs == null){return;}
            foreach(InputField input in ifs){
                  if(input == null) { continue;}
                  if(string.isNullOrEmpty(inputField.text) == true){ return; }

The IEnumerable of InputField may come from wherever you store the InputFields.

Any reason why XML over Json? The latter is lighter and I’d say easier to use (personal opinion).

This would be Json:

public class Controller:MonoBehaviour
     [SerializeField] private InputField[] inputs = null;
    public void SaveData(){
           ItemDatabase items = new ItemDatabase(this.inputs as IEnumerable<InputField>);
          string json = JsonUtility.ToJson(items);
          System.IO.File.WriteAllText(path, json);


This would be my first time using XML. I use XML like this:


but thanks for the answer I will try it.