You must Sign In to post a response.
  • Category: LINQ

    C# XML Data Reading display using LINQ

    xml data file name InitData.xml

    <root>
    <Document>
    <Type Icon = "Images.icon-Word.png" Name = "Microsoft Word" Code = "DOCX" DisplayOrder = "1" />
    <Type Icon = "Images.icon-Excel.png" Name = "Microsoft Excel" Code = "XLSX" DisplayOrder = "2" />
    </Document>
    </root>

    LINQ read

    XDocument document = XDocument.Load ("InitData.xml");
    var anonArray = from t in document.Descendants("Type")
    let xElement = t
    where xElement != null
    select new
    {
    Icon = xElement.Attribute("Icon").Value,
    Name = xElement.Attribute("Name").Value ,
    Code = xElement.Attribute("Code").Value,
    DisplayOrder = xElement.Attribute("DisplayOrder").Value
    };


    foreach (var v in anonArray)
    {
    console.writeline("{0} {1} {2} {3}", v.Icon, v.Name, v.Code, v.DisplayOrder );
    }
  • #746661
    Hi Ramanathan Nagappan,

    Can you please explain what exactly is the issue you are facing while using this code? You haven't written any details except the code.

    If you are trying to share this piece of code then please post it in article section.


    Regards,
    Asheej T K

  • #746677
    Above xml data to be displayed using JQuery/Typescript.

    Regards,
    Ram

  • #746721
    Try the below JQuery code to read and alert the XML element



    var xml = "<rss version='2.0'><channel><name>Anil Kumar</name></channel></rss>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $name = $xml.find( "name" );

    alert($name.text());

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments