Error in XML document

  • Thread starter Thread starter thereisnopatchforhumancruelty
  • Start date Start date
T

thereisnopatchforhumancruelty

Guest
Error in XML document (97, 124). - in System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) in System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

Hi, I have the following XML document:

<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema">
<r k="KEY1" v="VALUE1" />
<r k="KEY2" v="VALUE2" />
...
</items>



I tried to deserialize it doing the following operation:

private Dictionary<string, string> deserializeDictionary(string path)
{
Dictionary<string, string> deserializedDictionary = new Dictionary<string, string>();
StreamReader sr = File.OpenText(path);
XmlSerializer serializer = new XmlSerializer(typeof(r[]), new XmlRootAttribute() { ElementName = "items" });
deserializedDictionary = ((r[])serializer.Deserialize(sr)).ToDictionary(i => i.key, i => i.value);
sr.Close();
return deserializedDictionary;
}



where r is:

public class r
{
[XmlAttribute(AttributeName = "k")]
public string key;
[XmlAttribute(AttributeName = "v")]
public string value;
}

but at

deserializedDictionary = ((r[])serializer.Deserialize(sr)).ToDictionary(i => i.key, i => i.value);

line, an exception occurs:

Error in XML document (97, 124). - in System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) in System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

Why I get this error?

Thank You.


EDIT:

Inner Exception:

The character '&#1;', with hexadecimal value 0x01, is not valid. Line 97, position 124.

Continue reading...
 
Back
Top