title: How to Deserialize XML Attributes into objects, then iterate through the objects
body: <p>I would like to be able to 'do things' to the Vehicles in the XML file.  Ideally I want to iterate through all the vehicles and do a calculation on their price, and change whether they are OnSale.  These values would then be displayed in the UI.  My code deserializes the XML file but I am unable to access any of the attributes for the Vehicle.  I do not need to serialize the objects back to XML.</p>
  
  <p>I have tried to Console.WriteLine the Price, however when I run the code it is returned as 0.  Should I be creating an Array of ResponseGeographyVendorRegionVehicle? and then somehow adding objects of that type to the array?  </p>
  
  <p>This is the XML File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Response&gt;
    &lt;Geography&gt;
      &lt;Vendor id="JOHN"&gt;
        &lt;Region id="1"&gt;&lt;/Region&gt;
        &lt;Region id="2"&gt;
          &lt;Vehicle Make="HONDA" Fuel="Gas" Price="12000" OnSale="Y" Account="JOHNH" /&gt;
          &lt;Vehicle Make="ACURA" Fuel="Gas" Price="14100" OnSale="Y" Account="JOHNH" /&gt;
          &lt;Vehicle Make="TOYOTA" Fuel="Gas" Price="8000" OnSale="N" Account="JOHNH" /&gt;
          &lt;Vehicle Make="HYUNDAI" Fuel="Gas" Price="13000" OnSale="Y" Account="JOHNH" /&gt;
          &lt;Vehicle Make="INFINITY" Fuel="Gas" Price="16000" OnSale="N" Account="JOHNH" /&gt;
        &lt;/Region&gt;
        &lt;Region id="3"&gt;&lt;/Region&gt;
        &lt;Region id="4"&gt;&lt;/Region&gt;
      &lt;/Vendor&gt;
    &lt;/Geography&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>This is my Program.cs:</p>
  
  <pre><code>namespace XMLDeserializeExample
  {
      class Program 
      {
          static void Main(string[] args)
          {
              string path = @"c:\XMLFile1.xml";
              XmlRootAttribute xRoot = new XmlRootAttribute();
              xRoot.ElementName = "Response";
              XmlSerializer ser = new XmlSerializer(typeof(ResponseGeographyVendorRegionVehicle), xRoot);
              ResponseGeographyVendorRegionVehicle i;
              using (Stream reader = new FileStream(path,FileMode.Open)) 
              {
                  i = (ResponseGeographyVendorRegionVehicle)ser.Deserialize(reader);
                  Console.WriteLine(i.Price);
                  Console.ReadLine();
              }
          }
  
      }
  }
  </code></pre>
  
  <p>This is the Paste Special Response.CS file that was created:</p>
  
  <pre><code>namespace XMLDeserializeExample
  {
  }
  
  // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
  /// &lt;remarks/&gt;
  [System.SerializableAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
  public partial class Response
  {
  
      private ResponseGeography geographyField;
  
      /// &lt;remarks/&gt;
      public ResponseGeography Geography
      {
          get
          {
              return this.geographyField;
          }
          set
          {
              this.geographyField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.SerializableAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  public partial class ResponseGeography
  {
  
      private ResponseGeographyVendor vendorField;
  
      /// &lt;remarks/&gt;
      public ResponseGeographyVendor Vendor
      {
          get
          {
              return this.vendorField;
          }
          set
          {
              this.vendorField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.SerializableAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  public partial class ResponseGeographyVendor
  {
  
      private ResponseGeographyVendorRegion[] regionField;
  
      private string idField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute("Region")]
      public ResponseGeographyVendorRegion[] Region
      {
          get
          {
              return this.regionField;
          }
          set
          {
              this.regionField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string id
      {
          get
          {
              return this.idField;
          }
          set
          {
              this.idField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.SerializableAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  public partial class ResponseGeographyVendorRegion
  {
  
      private ResponseGeographyVendorRegionVehicle[] vehicleField;
  
      private byte idField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute("Vehicle")]
      public ResponseGeographyVendorRegionVehicle[] Vehicle
      {
          get
          {
              return this.vehicleField;
          }
          set
          {
              this.vehicleField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public byte id
      {
          get
          {
              return this.idField;
          }
          set
          {
              this.idField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.SerializableAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  public partial class ResponseGeographyVendorRegionVehicle
  {
  
      private string makeField;
  
      private string fuelField;
  
      private ushort priceField;
  
      private string onSaleField;
  
      private string accountField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string Make
      {
          get
          {
              return this.makeField;
          }
          set
          {
              this.makeField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string Fuel
      {
          get
          {
              return this.fuelField;
          }
          set
          {
              this.fuelField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public ushort Price
      {
          get
          {
              return this.priceField;
          }
          set
          {
              this.priceField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string OnSale
      {
          get
          {
              return this.onSaleField;
          }
          set
          {
              this.onSaleField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAttributeAttribute()]
      public string Account
      {
          get
          {
              return this.accountField;
          }
          set
          {
              this.accountField = value;
          }
      }
  }
  </code></pre>
  
  <p>Please let me know how I can better explain myself.  Apologies if none of this makes sense- welcome to my weekend lol.</p>
  
  <p>Thank you.</p>