locked
How can i convert this code to LINQ RRS feed

  • Question

  • User-1313990200 posted

    private XmlDocument FilterRecords(XmlDocument responseXml, int noOfRecords)
    {
    XElement envelope = XElement.Parse(responseXml.OuterXml);
    XElement envelopeAdd = new XElement("searchResultsList");

    foreach (XElement xe in envelope.Elements().Elements())
    {
    if (xe.Name.LocalName == "searchResultsList")
    {
    int count = 0;
    foreach (XElement childXe in xe.Elements())
    {
    if (count < noOfRecords)
    {
    if (childXe.Name.LocalName == "searchResultsRecord")
    {
    envelopeAdd.Add(childXe);
    count++;
    }
    }
    }
    }
    }

    Wednesday, October 30, 2019 3:35 AM

All replies

  • User1120430333 posted

    https://www.dotnetcurry.com/linq/564/linq-to-xml-tutorials-examples

    Maybe, a tutorial will help.

    Wednesday, October 30, 2019 8:09 AM
  • User665608656 posted

    Hi chandu,

    According to your description, do you want to query all the elements that meet the conditions through linq, and then add these elements to the envelopeAdd element you created?

    If this is the case, please provide the XML file source obtained by responsexml and what content you need to obtain or output in the end?

    I hope you can describe your needs in detail and provide detailed information, which will help us solve your problems easily.

    Best Regards,

    YongQing.

    Thursday, October 31, 2019 7:48 AM