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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:15:55+00:00 2026-05-11T21:15:55+00:00

Hi community I have the following problem, given this xml <test> <comp> <id>1</id> <content>bar</content>

  • 0

Hi community I have the following problem,

given this xml

<test>
    <comp>
        <id>1</id>
        <content>bar</content>
    </comp>
    <comp>
        <id>2</id>
        <content>foo</content>
    </comp>
</test>

I want to change the value of the content of the comp element with id 2. Therefore I loop with a foreach loop

for each (var x : XML in testXML.children()) {
                    if (x.id == 2) {
                        for each (var element : XML in x.Children()) {
                            if (element.localName() == "content") {
                                element = "new content";
                            }
                        }
                    }
                }

now when reaching the point element = "new content"; my programm tells me I cannot give element the value new content as this is a string and element is xml. How can I achieve this?

Thanks in advance

Sebastian

  • 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-11T21:15:55+00:00Added an answer on May 11, 2026 at 9:15 pm

    Try using E4X instead of loops.

    To access the element use:

    xml.comp.(id == 2).content
    

    To modify it’s contents, use

    xml.comp.(id == 2).content.* = "new content";
    

    Much shorter 🙂

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

Sidebar

Related Questions

Let's say I have a web site for hosting community generated content that targets
Since I'm sure many people have different standard, I've made this post a community
Problem Given the following two tables, I'd like to select all Ids for Posts
I have seen the ASP.NET community buzzing about MVC. I know the basics of
I have been using the Tigris community tasks to update various AppSettings keys using
I have an error occuring frequently from our community server installation whenever the googlesitemap.ashx
You may have noticed that we now show an edit summary on Community Wiki
I'm running Community Server 2.1 at the moment. My cs_PostViews table is at 200MB.
Hey stackoverflow community! I'm having an issue where a highly involved algorithmic program is
I'd like the community's take on some thoughts I've had about Linq to Sql

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.