Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

how to read xml elements using linq in c#.net recursively

$
0
0

2824 Points

628 Posts

how to read xml elements using linq in c#.net recursively.

a few seconds ago|mkonanki|LINK

Hi Could you any body know , how to read below xml input data using linq or some ohter way.

currently i am using below code which is giving count 1

 public class PassengerRemarks
    {
       public int remarks_item_num { get; set; }
       public string remarks_text { get; set; }
       public int rmrks_60_int_spr1 { get; set; }
       public int rmrks_60_int_spr2 { get; set; }
       public string rmrks_60_str_spr1 { get; set; }
       public string rmrks_60_str_spr2 { get; set; }
    }  

 using (StreamReader sr = new StreamReader(xmlString, true))
          {
              xdoc = XDocument.Load(sr, LoadOptions.PreserveWhitespace);

}

List<PassengerRemarks> result1 =
              (
                  from x in xdoc.Root.Elements("p_remarks_itms")
                  select new PassengerRemarks()
                  {
                      remarks_item_num = Convert.ToInt32(x.Element("remarks_item_num").Value),
                      rmrks_60_int_spr1 = Convert.ToInt32(x.Element("rmrks_60_int_spr1").Value),
                      remarks_text = x.Element("remarks_text").Value
                  }).ToList();

above code giving first list only

but below xml having more values with "Next" root element .

<p_remarks_itms>

    <remarks_item_num>1</remarks_item_num>

    <remarks_text>

      <value>ATTN ATO/RES..DO NOT CHANGE FLTS W/OUT APPROVAL OF CREW SCHEDULING</value>

    </remarks_text>

    <rmrks_60_int_spr1>0</rmrks_60_int_spr1>

    <rmrks_60_int_spr2>0</rmrks_60_int_spr2>

    <rmrks_60_str_spr1>

      <value />

    </rmrks_60_str_spr1>

    <rmrks_60_str_spr2>

      <value />

    </rmrks_60_str_spr2>

    <next>

      <remarks_item_num>2</remarks_item_num>

      <remarks_text>

        <value>BUSINESSFIRST.CLASS.MIN.REQUIRED.DO.NOT.UNSEAT/DOWNGRADE</value>

      </remarks_text>

      <rmrks_60_int_spr1>0</rmrks_60_int_spr1>

      <rmrks_60_int_spr2>0</rmrks_60_int_spr2>

      <rmrks_60_str_spr1>

        <value />

      </rmrks_60_str_spr1>

      <rmrks_60_str_spr2>

        <value />

      </rmrks_60_str_spr2>

      <next>

        <remarks_item_num>3</remarks_item_num>

        <remarks_text>

          <value>02 REMARKS ADDED BY WRC SU CS 21JAN 0027Z D13EC4</value>

        </remarks_text>

        <rmrks_60_int_spr1>0</rmrks_60_int_spr1>

        <rmrks_60_int_spr2>0</rmrks_60_int_spr2>

        <rmrks_60_str_spr1>

          <value />

        </rmrks_60_str_spr1>

        <rmrks_60_str_spr2>

          <value />

        </rmrks_60_str_spr2>

        <next>

          <remarks_item_num>4</remarks_item_num>

          <remarks_text>

            <value>PRPS ETICKET REQUESTED*40935</value>

          </remarks_text>

          <rmrks_60_int_spr1>0</rmrks_60_int_spr1>

          <rmrks_60_int_spr2>0</rmrks_60_int_spr2>

          <rmrks_60_str_spr1>

            <value />

          </rmrks_60_str_spr1>

          <rmrks_60_str_spr2>

            <value />

          </rmrks_60_str_spr2>

          <next>

            <remarks_item_num>5</remarks_item_num>

            <remarks_text>

              <value>01 REMARKS ADDED BY WRC SU CS 28JAN 0435Z D13EC4</value>

            </remarks_text>

            <rmrks_60_int_spr1>0</rmrks_60_int_spr1>

            <rmrks_60_int_spr2>0</rmrks_60_int_spr2>

            <rmrks_60_str_spr1>

              <value />

            </rmrks_60_str_spr1>

            <rmrks_60_str_spr2>

              <value />

            </rmrks_60_str_spr2>

          </next>

        </next>

      </next>

    </next>

  </p_remarks_itms>


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>