Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# .Select Method

C# .Select Method

Scheduled Pinned Locked Moved C#
csharpxmljsonhelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bootzilla33
    wrote on last edited by
    #1

    I want to do a .Select for the rest of the fields: EventStatus, EventReason, and EventDateTime like I'm doing for the TrackingEvent and am not sure how to do that. Richard Deeming was helpful in get me started with this but need help with the rest. TrackingEventHistory is the root for XML element I'm trying to output. The rest (EventStatus, EventReason, EventDateTime) are "children" within that root. There can be multiple TrackingEventHistory's so I'm trying to create a loop for the root and it's children. I'm not sure if .Select is the best way.

    new XElement("TrackingEventHistory",
    prc.History.Cast().Select(item => new XElement("TrackingEventDetail",
    new XElement("EventStatus", EventCode.Delivered.ToXml()),
    new XElement("EventReason", prc.History),
    new XElement("EventDateTime", prc.History))

    P 1 Reply Last reply
    0
    • B Bootzilla33

      I want to do a .Select for the rest of the fields: EventStatus, EventReason, and EventDateTime like I'm doing for the TrackingEvent and am not sure how to do that. Richard Deeming was helpful in get me started with this but need help with the rest. TrackingEventHistory is the root for XML element I'm trying to output. The rest (EventStatus, EventReason, EventDateTime) are "children" within that root. There can be multiple TrackingEventHistory's so I'm trying to create a loop for the root and it's children. I'm not sure if .Select is the best way.

      new XElement("TrackingEventHistory",
      prc.History.Cast().Select(item => new XElement("TrackingEventDetail",
      new XElement("EventStatus", EventCode.Delivered.ToXml()),
      new XElement("EventReason", prc.History),
      new XElement("EventDateTime", prc.History))

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Rather than wasting your time getting stuck, posting a question and waiting for a reply, you should take some time to learn the basics of how XLINQ works. Fortunately for you, Sacha Barber wrote an excellent article on this topic. You can find it here[^].

      This space for rent

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Rather than wasting your time getting stuck, posting a question and waiting for a reply, you should take some time to learn the basics of how XLINQ works. Fortunately for you, Sacha Barber wrote an excellent article on this topic. You can find it here[^].

        This space for rent

        B Offline
        B Offline
        Bootzilla33
        wrote on last edited by
        #3

        Would something like this work

        var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
        foreach (XElement element in query)
        {
        new XElement("EventStatus", EventCode.Delivered.ToXml()),
        Response.Write(element.Value);
        }

        P 2 Replies Last reply
        0
        • B Bootzilla33

          Would something like this work

          var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
          foreach (XElement element in query)
          {
          new XElement("EventStatus", EventCode.Delivered.ToXml()),
          Response.Write(element.Value);
          }

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Why not try it and find out?

          This space for rent

          1 Reply Last reply
          0
          • B Bootzilla33

            Would something like this work

            var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
            foreach (XElement element in query)
            {
            new XElement("EventStatus", EventCode.Delivered.ToXml()),
            Response.Write(element.Value);
            }

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            If you haven't downloaded it yet, you really should try out Linqpad[^]. Here's guidance[^] on how to query XLinq in it.

            This space for rent

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups