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

  • Home
  • SEARCH
  • 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 87153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:21:29+00:00 2026-05-10T22:21:29+00:00

Given the following XML ‘template’: <Request module=CRM call=list_service_features id={ID}> <block name=auth> <a name=username format=text>{USERNAME}</a>

  • 0

Given the following XML ‘template’:

<Request module='CRM' call='list_service_features' id='{ID}'>   <block name='auth'>      <a name='username' format='text'>{USERNAME}</a>      <a name='password' format='password'>{PASSWORD}</a>      <a name='client-id' format='counting'>{CLIENT-ID}</a>   </block>   <a name='service-id' format='counting'>{SERVICE-ID}</a> </Request> 

Using XDocument, what’s the best way to set the values in curly braces. I got so far but got stuck on the best way to select each of the three <a /> nodes inside the <block/> element. This is just a small fragment of XML, others may have up to 20 <a name='...'></a> elements.

The the way the XML is constructed wasn’t my creation, it’s what we have to sent to our supplier’s ‘web service’…before anyone has a laugh at the format=’counting’ attribute 🙂

@David – cheers for the response, appreciated. I was kinda hoping it’d be a bit more elegant, kinda along the lines of:

List<XElement> e = doc.Descendants('a').ToList(); e.Where(x => x.Attributes('name') == 'username').Single().Value = 'abc'; e.Where(x => x.Attributes('name') == 'password').Single().Value = 'abc'; 

Clearly the code above doesn’t work but I thought there would be an elegant one liner for each of the <a> tags

  • 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. 2026-05-10T22:21:30+00:00Added an answer on May 10, 2026 at 10:21 pm

    Does this do it for you? Good old Descendants property.

    string xmlInput = ...; XDocument myDoc = XDocument.Parse(xmlInput); // List<XElement> someElements = myDoc.Descendants('a').ToList(); someElements.ForEach(x => x.Value = 'Foo'); // Console.WriteLine(myDoc); 

    Hmm, I see you have an attribute in there. Can do that too:

    string xmlInput = //... XDocument myDoc = XDocument.Parse(xmlInput); // List<XText> someText =   myDoc.Descendants()   .Nodes()   .OfType<XText>()   .Where(x => x.Value.StartsWith('{') && x.Value.EndsWith('}'))   .ToList(); // List<XAttribute> someAttributes =   myDoc.Descendants()   .Attributes()   .Where(x => x.Value.StartsWith('{') && x.Value.EndsWith('}'))   .ToList(); // someText.ForEach(x => x.Value = 'Foo'); someAttributes.ForEach(x => x.Value = 'Bar'); // Console.WriteLine(myDoc); 

    Ah, now with what you’re expecting, I will make it work:

    List<XElement> e = myDoc.Descendants('a').ToList(); e.Where(x => x.Attribute('name').Value == 'username').Single().Value = 'abc'; e.Where(x => x.Attribute('name').Value == 'password').Single().Value = 'abc'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think it is the wrong idea to store all… May 11, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer I think it may work if you use the trigger… May 11, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer Use Annotations. If you mark the fields that you need… May 11, 2026 at 6:40 pm

Related Questions

Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>
Given the following XML 'template': <Request module=CRM call=list_service_features id={ID}> <block name=auth> <a name=username format=text>{USERNAME}</a>
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
Given the following XML: <databases> <database> <title_display>Aardvark</title_display> </database> <database> <title_display>Apple</title_display> </database> <database> <title_display>Blue</title_display> </database>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.