-1

I have a XML file like this,

<SellingCode>

<LastUpdated>2016-01-05T08:36:53+00:00</LastUpdated>

<SellingCodeID>5045460018689</SellingCodeID>

<SellingCodeID>103018090008</SellingCodeID>

<ProductID>1030180900</ProductID>

</SellingCode>

How do I produce the data like this

2016-01-05T08:36:53+00:00 | 5045460018689 | 1030180900

2016-01-05T08:36:53+00:00 | 103018090008  | 1030180900

Do you guys have any idea how I do it in c#?

Rommy
  • 447
  • 3
  • 10
  • 23
  • Possible duplicate of [LINQ to XML (C#) Iterate through nodes to build string?](http://stackoverflow.com/questions/16870843/linq-to-xml-c-iterate-through-nodes-to-build-string) and many others if you search. – Alex K. Mar 01 '16 at 11:28
  • 1
    Firstly, your XML is not in a correct format. Use a repeating group, http://stackoverflow.com/questions/15824975/best-practice-for-xml-repeating-elements – Murray Foxcroft Mar 01 '16 at 11:30
  • @MurrayFoxcroft Why shouldn´t this be valid Xml? It is absolutely valid to serialize the list-elements directly without any container-element. – MakePeaceGreatAgain Mar 01 '16 at 11:34
  • @HimBromBeere - you are correct. I stand corrected. – Murray Foxcroft Mar 01 '16 at 12:12

2 Answers2

0

Deserialize to the following class and then iterate / lync to get the format you are after.

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class SellingCode
{

    private System.DateTime lastUpdatedField;

    private ulong[] sellingCodeIDField;

    private uint productIDField;

    /// <remarks/>
    public System.DateTime LastUpdated
    {
        get
        {
            return this.lastUpdatedField;
        }
        set
        {
            this.lastUpdatedField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("SellingCodeID")]
    public ulong[] SellingCodeID
    {
        get
        {
            return this.sellingCodeIDField;
        }
        set
        {
            this.sellingCodeIDField = value;
        }
    }

    /// <remarks/>
    public uint ProductID
    {
        get
        {
            return this.productIDField;
        }
        set
        {
            this.productIDField = value;
        }
    }
}
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
-1

LINQ to XML will work for you.

var document = XDocument.Load("file.xml");
var array = document.Descendants("COL").Select(x => (int) x).ToArray();
Ultradiv
  • 179
  • 2
  • 11