Example #1
0
    public void ReadXml(XmlReader reader)
    {
        reader.ReadStartElement(); //wrapping element

        this.name = reader.ReadElementContentAsString();
        this.extension = reader.ReadElementContentAsString();

        string tempFileName = Path.GetTempFileName();
        this.streamFileName = tempFileName;
        using (FileStream fs = File.Create(tempFileName))
        {
            byte[] buffer = new byte[1000];
            int bytesRead;
            reader.ReadStartElement();
            do
            {
                bytesRead = reader.ReadContentAsBase64(buffer, 0, buffer.Length);
                fs.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);

            reader.ReadEndElement();
        }

        reader.ReadEndElement(); //wrapping element
    }
		 void IXmlSerializable.ReadXml(XmlReader r)
		{
			r.MoveToContent();
			r.ReadStartElement("Employee");
			
			 r.ReadStartElement("Name");
			 FirstName = r.ReadElementString("First", ns);
			 LastName = r.ReadElementString("Last", ns);
			r.ReadEndElement();
			r.MoveToContent();
			 ID = Int32.Parse(r.ReadElementString("ID", ns));
			 r.ReadEndElement();
			 
		}
	private void LoadEnemies(XmlReader reader) {
		reader.ReadStartElement("Enemies");

		GameObject enemy = null;
		bool enemyToParse = reader.ReadToFollowing ("Enemy");
		Debug.Log ("Started parsing enemies..." + enemyToParse);
		do {
			if(!enemyToParse)
				break;
			
			Debug.Log ("Found an enemy");
			switch (reader.GetAttribute ("Type")) {
			case "Bat":
				enemy = Instantiate (prefabDictionary ["Bat"]);
				break;
			case "Blob":
				enemy = Instantiate (prefabDictionary ["Blob"]);
				break;
			} 
			enemy.GetComponent<Enemy> ().Load (reader);
		} while(reader.ReadToNextSibling("Enemy"));

	}
        public static void ReadObject(XmlReader reader, object obj, PropertyConversionHandler handler = null)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            reader.MoveToContent();

            if (obj is IXmlSerializable)
            {
                ((IXmlSerializable)obj).ReadXml(reader);
            }
            else
            {
                object oVal = null;
                string oName = GetAttributeValue(obj.GetType(), typeof(XmlRootAttribute), "ElementName", true, ref oVal) ? oVal.ToString() : obj.GetType().Name;
                if (reader.LocalName != oName)
                    throw new XmlException("XML element name does not match object.");

                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                    reader.MoveToContent();
                    ReadObjectProperties(reader, obj, handler);
                    reader.ReadEndElement();
                }
                else
                    reader.Skip();
            }
        }