internal void ReadXml(XmlTextReader reader) { while (reader.Read()) { // End of invoice element, get out of here if (reader.Name == "invoice" && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "id": this.Id = reader.ReadElementContentAsString(); break; case "account_code": this.AccountCode = reader.ReadElementContentAsString(); break; case "date": DateTime date; if (DateTime.TryParse(reader.ReadElementContentAsString(), out date)) { this.Date = date; } break; case "invoice_number": int invNumber; if (Int32.TryParse(reader.ReadElementContentAsString(), out invNumber)) { this.Number = invNumber; } break; case "line_items": LineItems.ReadXml(reader); break; case "payments": Payments.ReadXml(reader); break; } } } }