Linq to XML CDATA Help

I have the below code where I am trying to pull out the values for each field's "nv" and "ov" (if ov exists) under its parent entry. However, my code is returning three items for each field, example shown below. I'm not sure why it's doing this and I really only want the first line since it contains everything.

Is there an easier way to extract this information by looping through each field pulling out the nv and ov values?

<field name="HROrganization" t="0" s="4" d="0"><nv><![CDATA[LC]]></nv></field>
<nv><![CDATA[LC]]></nv>
<field name="Employee" t="1" s="13" d="0"><nv><![CDATA[90102001]]></nv></field>
<nv><![CDATA[90102001]]></nv>

...NEXT ENTRY...
<field name="PrimaryWorkAssignment" t="1" s="4" d="0"><ov><![CDATA[0]]></ov><nv><![CDATA[1]]></nv></field>
<ov><![CDATA[0]]></ov>
<nv><![CDATA[1]]></nv>

            XDocument doc = XDocument.Load("employee.xml");

            IEnumerable<XElement> entries = (from entry in doc.Root.Elements("entry")
                                             select entry);

            foreach (XElement entry in entries)
            {
                IEnumerable<XElement> fields = doc.Root.Descendants("entry")
                    .Where(x => x.Attribute("timestamp") == entry.Attribute("timestamp"))
                    .First()
                    .Descendants();

                foreach(XElement field in fields)
                {
                   // ...loop through each field but there are 3 records for each field
                }
            }

Open in new window


XML
<log>
   <entry timestamp="2011122818084801" actor="1234" authenticatedactor="SYSTEM" effective="20030224" caller="EmployeeImport.CreateAllEmployees" action="ImportRecord" type="create" s="HCM" id="01346688-b157-0000-0000-0b404e08dd31">
      <field name="HROrganization" t="0" s="4" d="0">
         <nv><![CDATA[XYZ]]></nv>
      </field>
      <field name="Employee" t="1" s="13" d="0">
         <nv><![CDATA[12345678]]></nv>
      </field>
      <field name="Name.FormOfAddress" t="30" s="50" d="0">
         <nv />
      </field>
      <field name="Name.GivenName" t="30" s="50" d="0">
         <nv><![CDATA[Bill]]></nv>
      </field>
      <field name="Name.PreferredGivenName" t="30" s="50" d="0">
         <nv><![CDATA[Bill]]></nv>
      </field>
      <field name="Name.MiddleName" t="30" s="50" d="0">
         <nv />
      </field>
      <field name="AnniversaryDate" t="5">
         <nv><![CDATA[20030224]]></nv>
      </field>
	</entry>
	<entry timestamp="2011122818113424" actor="1156" authenticatedactor="SYSTEM" effective="20101101" caller="WorkAssignment.ImportRecord" action="SetPrimaryWorkAssignment" type="update" s="HCM" id="01346688-b157-0000-0000-15a54e08dd31">
      <field name="PrimaryWorkAssignment" t="1" s="4" d="0">
         <ov><![CDATA[0]]></ov>
         <nv><![CDATA[1]]></nv>
      </field>
   </entry>
   <entry timestamp="2011122818170512" actor="1156" authenticatedactor="SYSTEM" effective="20030224" caller="EmployeeAddress.Create" action="UpdateAddress" type="update" s="HCM" id="01346688-b157-0000-0000-223e4e08dd31">
      <field name="UseForMailing" t="1" s="6" d="0">
         <ov><![CDATA[0]]></ov>
         <nv><![CDATA[1]]></nv>
      </field>
      <field name="UseForPayroll" t="1" s="6" d="0">
         <ov><![CDATA[0]]></ov>
         <nv><![CDATA[1]]></nv>
      </field>
   </entry>
   <entry timestamp="2011122818180659" actor="1156" authenticatedactor="SYSTEM" effective="20030224" caller="EmployeeContact.Create" action="UpdateContact" type="update" s="HCM" id="01346688-b157-0000-0000-2cba4e08dd31">
      <field name="UseForWorkPhone" t="1" s="6" d="0">
         <ov><![CDATA[0]]></ov>
         <nv><![CDATA[2]]></nv>
      </field>
   </entry>
   <entry timestamp="2011122818242343" actor="1156" authenticatedactor="SYSTEM" effective="20030224" caller="EmployeeContact.Create" action="UpdateContact" type="update" s="HCM" id="01346688-b157-0000-0000-36684e08dd31">
      <field name="UseForWorkEmail" t="1" s="6" d="0">
         <ov><![CDATA[0]]></ov>
         <nv><![CDATA[4]]></nv>
      </field>
   </entry>
   <entry timestamp="2012020723573088" actor="2056" authenticatedactor="2056" effective="20120101" caller="Employee.Update" action="Update" type="update" s="HCM" id="01350d8d-4c99-0000-0000-9a114e08dd31">
      <field name="Nationality" t="0" s="20" d="0">
         <ov />
         <nv><![CDATA[01. ENGLISH]]></nv>
      </field>
      <field name="NationalityCountry" t="0" s="3" d="0">
         <ov />
         <nv><![CDATA[US]]></nv>
      </field>
   </entry>
   <entry timestamp="2012022918363888" actor="2056" authenticatedactor="2056" effective="20120102" caller="Employee.Update" action="Update" type="update" s="HCM" id="0135c24c-60a8-0000-0000-40d74e08dd31">
      <field name="AdjustedStartDate" t="5">
         <ov><![CDATA[00000000]]></ov>
         <nv><![CDATA[20030224]]></nv>
      </field>
   </entry>
</log>

Open in new window

nightshadzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi nightshadz;

Parsing through your XML document what do you want to be returned after it is completed?

Can you post what you want for each entry node so we can post what you are looking for.
nightshadzAuthor Commented:
I was able to figure it out with some trial and error. Thanks for checking in though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nightshadzAuthor Commented:
Answered my own issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.