XML Error on Load

Hi Y’all!

Whenever I try to fetch data from the xml I’m throw this error:

XmlException: Expected >, but found s
[115] Line 7, position 9.
Mono.Xml2.XmlTextReader.ExpectAfterWhitespace
(Char c)
Mono.Xml2.XmlTextReader.ReadEndTag ()
Mono.Xml2.XmlTextReader.ReadContent ()

Anyone got a clue whats going on?

Thanks! :slight_smile:

item.xml:

<ItemCollection>
	<Items>
		<Item>
			<Item name="r">
			<Damage>32</Damage>
		</Item>
	</Items>
</ItemCollection>

ItemContainer.cs:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;

[XmlRoot("ItemCollection")]

public class ItemContainer {
	[XmlArray("Items")]
	[XmlArrayItem("Item")]
	public List<BaseItem> items = new List<BaseItem>();

	public static ItemContainer Load(string path)
	{
		TextAsset _xml = Resources.Load(path) as TextAsset;

		XmlSerializer serializer = new XmlSerializer(typeof(ItemContainer));
		Debug.Log(_xml.text);
		StringReader reader = new StringReader(_xml.text);

		ItemContainer items = serializer.Deserialize(reader) as ItemContainer;

		reader.Close();
		 
		return items;
	}
}

You’re starting two Item tags on lines 3 and 4, but only closing one on line 6, so it’s expecting line 7 to be a closing Item tag and not Items. You can close the second Item without needing a separate close tag like this:

<Item name="r"/>