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 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
  • 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. 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

Related Questions

Given the following XML: <root> <StepFusionSet name=SF1> <StepFusionSet name=SF2> </StepFusionSet> </StepFusionSet> <StepFusionSet name=SF10> </StepFusionSet>
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <application name=foo> <movie name=tc english=tce.swf chinese=tcc.swf
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema> <sequence>
Given the following XML markup: <root xmlns=Demo> <child name=foo/> </root> and an XPathNavigator positioned
Given the following XML: <results name=queryResults> <int name=intfield1:[* TO 10]>11</int> <int name=intfield2:[10 TO 20]>9</int>
Given the following XML file: <users> <user name=admin password=foobar roles=Admin,Guest /> <user name=guest password=foobar
Given the following Xml: <Animals xmlns=http://www.company.com/Global/US> <Mammals> <Animal> <Type> <Name>Cat</Name> <Breed>Ally Cat</Breed> </Type> <Color>
Given the following XML: <LiveScores> <Competition id=4915 name=Comp1 type=Union group=> <Match id=1678 round=No Round
Problem Given the following XML configuration file: <main> <name>JET</name> <maxInstances>5</maxInstances> <parameters> <a>1</a> <b> <b1>test1</b1>
I have the following xml. Given, a UID , Manufacturer Name and Image Layout

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.