Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can make this super simple. Object oriented programming is the way to go.</p> <p>So say you create a class Order that takes an XElement. I'll write a couple lines for you.</p> <pre><code>public class Order { XElement self; public Order(XElement order) { self = order; } public XElement Element { get { return self; } } public string OrderNumber { // if your xml looks like &lt;Order OrderNumber="somenumber" /&gt; get { return (string)(self.Attribute("OrderNumber") ?? (object)"some default value/null"); } // but if it looks like: &lt;Order&gt;&lt;OrderNumber&gt;somenumber&lt;/OrderNumber&gt;&lt;/Order&gt; // get { return (string)(self.Element("OrderNumber") ?? (object)"some default value/null"); } } } </code></pre> <p>You'll have to fill in the rest of the Order's properties yourself. For each Order value, make a property like the OrderNumber I made above. Having properties for each Order value makes accessing the data super simple.</p> <p>So for your main code you'd have:</p> <pre><code>XElement file = XElement.Load(@"C:\onlinesales\neworders.xml"); Order[] orders = file.Elements("Order").Select(e =&gt; new Order(e)).ToArray(); </code></pre> <p>Now that you have all your orders as individual Order objects, read the data from the list of properties as you output to the file. There's no need now to store the values in StringBuilder's because the values are in the Order objects.</p> <pre><code>foreach(Order order in orders) { // write order.OrderNumber etc. / do whatever you want with the orders. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload