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 8660525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:16:25+00:00 2026-06-12T16:16:25+00:00

I have a xmlNodeList as <Fields> <Field FieldId=1 Value=123 FieldTitle=id FieldType=Text/> <Field FieldId=2 Value=abc

  • 0

I have a xmlNodeList as

<Fields>
  <Field FieldId="1" Value="123" FieldTitle="id" FieldType="Text"/>
  <Field FieldId="2" Value="abc" FieldTitle="First Name" FieldType="Text"/>
  <Field FieldId="3" Value="efg" FieldTitle="Last Name" FieldType="Text"/>
</Fields>

now what I want is

var id        = 123   //select the `value` if `FieldId == "1";
var firstName = abc   //select the `value` if `FieldId == "2";
var last name = efg  //select the `value` if `FieldId == "3";

Edit: I don’t want to loop threw the fields and check every field with if condition.

One liner solution is most welcome.

NOTE: I am dealing with very large XML and the Fields is a part of single node and there are about 500 fields of thousand of nodes, any other better solution to convert this much larger XML file into insert queries is most welcome

  • 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-06-12T16:16:26+00:00Added an answer on June 12, 2026 at 4:16 pm

    You can have fairly good idea, how to get it done by using this piece of code:

    XDocument doc = XDocument.Load(@"XmlFile1.xml");
    var elem = doc.Descendants("Field");
    
    var id = elem.Where(c => c.Attribute("FieldId").Value.Equals("1")).Select(s => s.Attribute("Value").Value).FirstOrDefault();
    var firstName = elem.Where(c => c.Attribute("FieldId").Value.Equals("2")).Select(s => s.Attribute("Value").Value).FirstOrDefault();
    var lastName = elem.Where(c => c.Attribute("FieldId").Value.Equals("3")).Select(s => s.Attribute("Value").Value).FirstOrDefault();
    

    One liner solution is not really possible as there is no way to segregate data between id, firstName, and lastName in one line of code.

    ADDED:

    var result = doc.Descendants("Field").Select(s => new { Field = s.Parent.GetHashCode(), FieldId = s.Attribute("FieldId").Value, Value = s.Attribute("Value").Value });
    foreach (var val in result.GroupBy(g => g.Field).Select(s => s))
    {
        var id = result.Where(c => c.Field == val.Key && c.FieldId == "1").Select(s => s.Value).FirstOrDefault();
        var firstName = result.Where(c => c.Field == val.Key && c.FieldId == "2").Select(s => s.Value).FirstOrDefault();
        var lastName = result.Where(c => c.Field == val.Key && c.FieldId == "3").Select(s => s.Value).FirstOrDefault();
        // ... do something ...
    }
    

    Hope this newly added code would give you some better idea 🙂

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

Sidebar

Related Questions

I have following xml file: <os:tax> <os:cat name=abc id=1> <os:subcat name=bcd id=11> <os:t name=def
I have XML like: <RES> <MUL> <SIN> <KEY name=a> <VALUE>a1</VALUE> </KEY> <KEY name=b> <VALUE>b1</VALUE>
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have an XmlNodeList that contains packets (item) from the root of the XML
I created xmlnodelist and i want to handle the value of elements that dont
I have a method in C# that finds a node with name node_name in
I have a external library that requires a XmlNode[] instead of XmlNodeList. Is there
I have this document where i want to get to the value in x_server_response/retrieve_resources_by_category_response/source_full_info/record/
I have found lots of examples of this using XmlNodeList but sadly WP7 does
I have been trying to read an xml file. I have to extract value

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.