web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

C# XML Nodes

(0) ShareShare
ReportReport
Posted on by 445

Hello Experts,

i have a problem with nodes from a xml file.

I have some <eventitem> nodes and want to loop every item in a variable, but i only get the first one...

<events>Liste</events>
<eventitem>Mitgliederversammlung</eventitem>
<eventitem>Sechzig Jahre</eventitem>

//SEMINARSELEKTION

                                    workshopstring = node["eventitem"].InnerText;
                                    

                                        if (workshopstring.Contains("Tag"))
                                        {

                                            TDMRTeilnahme = true;

                                            TDMRTeilnahme1.Set(executionContext, TDMRTeilnahme);
                                            tracingService.Trace("TDMRTeilnahme zugeordnet");

                                        }
                                        else if (workshopstring.Contains("Masch"))
                                        {

                                            tedx = true;
                                            TedX.Set(executionContext, tedx);
                                            tracingService.Trace("Teilnahme");
                                        }
                                        else
                                        {
                                            QueryExpression workshopquery = new QueryExpression("mrd_seminar");
                                            workshopquery.ColumnSet = new ColumnSet(true);
                                            workshopquery.Criteria.AddCondition("mrd_name", ConditionOperator.Equal, workshopstring);

                                            // query ausführen
                                            EntityCollection retrieveworkshop = service.RetrieveMultiple(workshopquery);

                                            if (retrieveworkshop.Entities.Count == 1)
                                            {
                                                                                              
                                                Entity Workshop1 = retrieveworkshop.Entities[0];
                                                Entity Workshop2 = retrieveworkshop.Entities[0];
                                                Entity Workshop3 = retrieveworkshop.Entities[0];
                                                Entity Workshop4 = retrieveworkshop.Entities[0];

                                                if (Workshop1 != null)
                                                {
                                                    WorkshopA.Set(executionContext, new EntityReference("mrd_seminar", Workshop1.Id));
                                                    tracingService.Trace("Workshop zugeordnet ", Workshop1.ToString());
                                                }
                                                else if (Workshop2 != null)
                                                {
                                                    WorkshopA.Set(executionContext, new EntityReference("mrd_seminar", Workshop2.Id));
                                                    tracingService.Trace("Workshop zugeordnet ", Workshop2.ToString());
                                                }
                                                else if (Workshop3 != null)
                                                {
                                                    WorkshopA.Set(executionContext, new EntityReference("mrd_seminar", Workshop3.Id));
                                                    tracingService.Trace("Workshop zugeordnet ", Workshop3.ToString());
                                                }
                                                else if (Workshop4 != null)
                                                {
                                                    WorkshopA.Set(executionContext, new EntityReference("mrd_seminar", Workshop4.Id));
                                                    tracingService.Trace("Workshop zugeordnet ", Workshop4.ToString());
                                                }

                                            }

                                        }

                                    //Variable clearen
                                    tracingService.Trace(workshopstring);
                                    workshopstring = null;
                                    return;

                                    //ENDE SEMINARVERGABE


Kind Regards
Léon

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello Léon,

    Which class are you using to read your XML?

     

    1. If you are using System.Xml.Linq.XDocument you can do this:
      IEnumerable<System.Xml.Linq.XElement> elements = doc.Document.Elements("eventitem");
      foreach(System.Xml.Linq.XElement element in elements) {
         // Loop...
      }

       

    2. If you are using System.Xml.XmlDocument, you can do this:
      System.Xml.XmlNodeList nodes = doc.DocumentElement.SelectNodes("//eventitem");
      foreach(System.Xml.XmlNode node in nodes)
      {
         // Loop...
      }
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi,

    Not sure why you are doing the following:

    Entity Workshop1 = retrieveworkshop.Entities[0];

    Entity Workshop2 = retrieveworkshop.Entities[0];

    Entity Workshop3 = retrieveworkshop.Entities[0];

    Entity Workshop4 = retrieveworkshop.Entities[0];

    They all return the exact same value, since your are setting this to the first entity:

    All you need is:

    Entity workshop = retrieveworkshop.Entities[0];

    Can you expand on what you are trying to do?

    For querying Xml you need to add a loop or you can use Linq To Xml.

    Check the following doc on how to query descendants:

    docs.microsoft.com/.../how-to-find-descendants-with-a-specific-element-name

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello Leon ,

    Could you please check below article.I hope you can get help from there

    www.csharp-examples.net/xml-nodes-by-name

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans