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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:04:27+00:00 2026-05-16T08:04:27+00:00

I have an XmlDocument object and xml in the format: <?xml version=1.0 encoding=utf-8?> <S

  • 0

I have an XmlDocument object and xml in the format:

<?xml version="1.0" encoding="utf-8"?>
<S xmlns="http://server.com/DAAPI">
    <TIMESTAMP>2010-08-16 17:25:45.633</TIMESTAMP>
    <MY_GROUP>
        <GROUP>1 </GROUP>
        <NAME>Amsterdam</NAME>
        ....
    </MY_GROUP>
    <MY_GROUP>
        <GROUP>2 </GROUP>
        <NAME>Ireland</NAME>
        ....
    </MY_GROUP>
    <MY_GROUP>
        <GROUP>3 </GROUP>
        <NAME>UK</NAME>
        ....
    </MY_GROUP>

Using a Lambda expression (or Linq To XML if it’s more appropriate) on the XmlDocument object how can i do the following:

  1. get the text of a specific element, say the text of NAME where GROUP = 1
  2. the value of the first occurance of the element “NAME”

Thanks a lot

  • 1 1 Answer
  • 1 View
  • 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-16T08:04:27+00:00Added an answer on May 16, 2026 at 8:04 am

    I have used Linq to XML.

    string input = "<?xml version=\"1.0\" encoding=\"utf-8\"?><S xmlns=\"http://server.com/DAAPI\"><TIMESTAMP>2010-08-16 17:25:45.633</TIMESTAMP><MY_GROUP><GROUP>1 </GROUP><NAME>Amsterdam</NAME>....</MY_GROUP><MY_GROUP><GROUP>2 </GROUP><NAME>Ireland</NAME>....</MY_GROUP><MY_GROUP><GROUP>3 </GROUP><NAME>UK</NAME>....</MY_GROUP></S>";
    
    var doc = XDocument.Parse(input);
    
    XNamespace ns = "http://server.com/DAAPI";
    
    //The first question
    var name = (from elem in doc.Root.Elements(ns + "MY_GROUP")
                where elem.Element(ns  + "GROUP") != null    //Checks whether the element actually exists - if you KNOW it does then it can be removed
                    && (int)elem.Element(ns + "GROUP") == 1  //This could fail if not an integer - insure it is if nessasary
                select (string)elem.Element(ns + "NAME")).SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have a System.Xml.XmlDocument object and I want to change the xml Encoding from
I have written some code that loads an XML document using an XmlDocument object
I have new XmlDocument object, i.g. xml is created during my program... I want
I have some XML that has creating using an XmlDocument object in C#. I
I have an loaded some XML in an XMLDocument object. I am iterating through
I have an XML document that I generate from an Entity Framework object. The
I have an XDocument object and the ToString() method returns XML without any indentation.
This one is a little tricky. Say I have this XmlDocument <Object> <Property1>1</Property1> <Property2>2</Property2>
I have a .Net webserivce that accepts XML in string format. XML String sent

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.