Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Parsing childnode attribute values from parent node only
    primarykey
    data
    text
    <p>Let's say we have the following XML file which look likes</p> <pre><code>&lt;model uri="model1"&gt; &lt;PriceData&gt; &lt;value price="24.28" date="2013-12-01"/&gt; &lt;value price="22.34" date="2013-12-02"/&gt; &lt;value price="24.12" date="2013-12-03"/&gt; &lt;/PriceData&gt; &lt;/model&gt; &lt;model uri="model2"&gt; &lt;PriceData&gt; &lt;value price="24.28" date="2013-12-01"/&gt; &lt;value price="22.34" date="2013-12-02"/&gt; &lt;value price="24.12" date="2013-12-03"/&gt; &lt;/PriceData&gt; &lt;/model&gt; </code></pre> <p>and this can continue for many models and prices. I search a way to parse in different lists (or array) the price of each model without do it manually i.e. to preallocate lists etc. because the number of the model will not be the same all the time. So how can i make "buckets" of prices for different models? What i tried until now is</p> <pre><code>using System; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections.Generic; namespace test { class Program { static void Main(string[] args) { string file = @"C:\Users\user\Desktop\test.xml"; XDocument doc = XDocument.Load(file); List&lt;string&gt; priceData = new List&lt;string&gt;(); List&lt;string&gt; modelName = new List&lt;string&gt;(); foreach (var imovel in doc.Root.Descendants("model")) { modelName.Add(imovel.Attribute("uri").Value); } int modelNum = modelName.Count(); foreach (var item in doc.Descendants("value")) { var doubleAttr = item.Attribute("price"); if (doubleAttr == null) continue; priceData.Add(item.Attribute("price").Value); } //Console.WriteLine(modelName[0]); Console.ReadKey(); } } } </code></pre> <p>But in this case the second foreach loop takes the prices of all models in a list. I try to get some ideas...my cup of coffee is empty :-(</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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