<?xml version="1.0"?>
<!--
  Created by Wong Kai Chong
  BSPI 2017
  Temasek Polytechnic
-->
<order>
  <!-- Simple Type - Main Data -->
  <invoiceid>0011995</invoiceid>
  <invoicedate>12/5/2017</invoicedate>
  <sellerid>0020</sellerid>
  <buyerid>1231</buyerid>
  <orderid>9021</orderid>
  <!-- An Item - Multiple -->
  <item>
    <itemid>0001</itemid>
    <itemname>Apple Macbook Pro</itemname>
    <description>The best professional laptop for professionals.</description>
    <quantity>5</quantity>
    <newunitprice>4950.50</newunitprice>
  </item>
  <!-- An Item - Multiple -->
  <item>
    <itemid>0002</itemid>
    <itemname>Microsoft Surface Laptop</itemname>
    <description>The most versatile professional laptop for experts.</description>
    <quantity>10</quantity>
    <newunitprice>3500.90</newunitprice>
  </item>
  <!-- An Item - Multiple -->
  <item>
    <itemid>0003</itemid>
    <itemname>Apple iPhone</itemname>
    <description>The best consumer mobile phone.</description>
    <quantity>1000</quantity>
    <newunitprice>500.00</newunitprice>
  </item>
  <!-- An Item - Multiple -->
  <item>
    <itemid>0004</itemid>
    <itemname>Samsung Galaxy S8</itemname>
    <description>The most amazing screen on a phone.</description>
    <quantity>3000</quantity>
    <newunitprice>550.00</newunitprice>
  </item>
  <!-- Simple Type - Footer Data -->
  <shippingcharges>7000.00</shippingcharges>
  <invoicetotalcost>19500.10</invoicetotalcost>
</order>
And at the bottom here is the Visual Studio C# codes.
        string url = "../../../invoiceData.xml";
        XmlReader reader = XmlReader.Create(url);
        StringBuilder orderList = new StringBuilder();
        orderList.Append("Order List: ").Append(Environment.NewLine);
        int counter = 0;
        while (reader.ReadToFollowing("item"))
        {
            counter++;
            orderList.Append("Invoice counter: " + counter + Environment.NewLine);
            reader.ReadToFollowing("invoiceID");
            orderList.Append("Invoice ID: " + reader.ReadElementContentAsString() + Environment.NewLine);
            reader.ReadToFollowing("invoiceid");
            orderList.Append("Invoice ID: " + reader.ReadElementContentAsString());
            reader.ReadToFollowing("invoicedate");
            orderList.Append("Invoice Date: " + reader.ReadElementContentAsString());
        }``
This will be for my homework. So you will be helping a lot. The problem here is I don't know if my invoiceData.xml is even correct. And if it is, how do I write the codes to read them?
    string url = "../../invoice1.xml"; // assume args[0] is invoice1.xml
    XmlReader reader = XmlReader.Create(url);
    StringBuilder invoiceList = new StringBuilder();
    invoiceList.Append("Order List:").Append(Environment.NewLine);
    int counter = 0;
    while (reader.ReadToFollowing("order")) //read to each order element
    {
        counter++; //increase the counter
        invoiceList.Append("Order Counter: " + counter + Environment.NewLine);
        reader.ReadToFollowing("orderID"); //move to orderID element
        invoiceList.Append("Order ID: " + reader.ReadElementContentAsString() + Environment.NewLine); // read OrderID element content
        reader.ReadToFollowing("item"); //move to item element
        int itemCount = 1;
        invoiceList.Append("item: "+itemCount + reader.ReadElementContentAsString() + Environment.NewLine); // read item element content
        while (reader.ReadToNextSibling("item")) //move to next item element
        {
            itemCount++;
            invoiceList.Append("item: "+itemCount + reader.ReadElementContentAsString() + Environment.NewLine); // read item element content
        }
        reader.ReadEndElement();
This 3rd segment of codes are given to me as an example. They work as a boilerplate for me to modify and personalise to fit my solution. If you could, are you able to explain it in a way where I can understand these codes in order to personify for myself?
Best, KAI
 
    