Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:42:18+00:00 2026-05-27T04:42:18+00:00

This is the XML I’m trying to parse. I’m having trouble parsing the entry

  • 0

This is the XML I’m trying to parse. I’m having trouble parsing the entry elements and getting the different values within them. Usually I can specify the element that I’m trying to get at and extract the value from it. However, this time the elements I’m targeting all have the same name.

    <?xml version="1.0" encoding="UTF-8"?>
    <response id="-46056350:133f0f5eff1:54e3">
      <userdata>
        <account>
          <account>23408234</account>
        </account>
        <disabled>false</disabled>
        <resetpassword>false</resetpassword>
        <userprofile>
          <entry>
            <name>primaryMiddleInitial</name>
            <value/>
          </entry>
          <entry>
            <name>primaryLastName</name>
            <value>chen</value>
          </entry>
          <entry>
            <name>login_id</name>
            <value>Negative</value>
          </entry>
          <entry>
            <name>zip</name>
            <value/>
          </entry>
          <entry>
            <name>primaryFirstName</name>
            <value>eric</value>
          </entry>
          <entry>
            <name>emailAddress1</name>
            <value>ECHEN57@GMAIL.COM</value>
          </entry>
        </userprofile>
      </userdata>
      <error>Success</error>
    </response>

And this is my attempt at parsing it.

    public static MemberViewModel ParseMemberXML(string xml)
    {
        XDocument data = XDocument.Parse(xml);

        return (from c in data.Descendants("userdata")
                select new MemberViewModel()
                {
                    Account = c.Element("account").Element("account").Value,
                    PrimaryFirstName = c.Element("userprofile").Element("entry").Element("value").Value
                    PrimaryLastName
                    PrimaryMiddleInitial
                    LoginID

                }).ToList().ElementAt(0);
    }

How would I parse this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:42:19+00:00Added an answer on May 27, 2026 at 4:42 am

    Your best bet is to iterate over the “entry” elements and assign their values to fields of the MemberViewModel object as you discover them.

    Something like this:

     public static MemberViewModel ParseMemberXML(string xml)
     {
        XDocument data = XDocument.Parse(xml);
    
        // expecting exactly one
        XElement userdata = data.Root.Element("userdata");
    
        var obj = new MemberViewModel();
        obj.Account = userdata.Element("account").Element("account").Value;
    
        foreach (var entry in userdata.Element("userprofile").Elements("entry"))
        {
            switch (entry.Element("name").Value)
            {
                case "primaryFirstName": obj.PrimaryFirstName = entry.Element("value").Value; break;
                case "primaryLastName": obj.PrimaryLastName = entry.Element("value").Value;
        ...etc...
            }
        }
    
        return obj;
    }
    

    You could instead use XPath expressions to select individual elements by specifying their parentage path, but frankly I think the foreach loop is more manageable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse out this xml file to get a list of Elements but
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
Having this XML view: <?xml version=1.0 encoding=utf-8?> <LinearLayout android:id=@+id/myScrollLayout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical xmlns:android=http://schemas.android.com/apk/res/android> <ScrollView
this XML works different on 2.3 and 4.0. one of that shows table row
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i have this xml: <user> <name>H &amp; M</name> and i parse it using this
I've got this XML file that I am parsing using the parser here and
This XML file contained archived news stories for all of last year. I was
For this xml (in a SQL 2005 XML column): <doc> <a>1</a> <b ba="1" bb="2"
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.