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

The Archive Base Latest Questions

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

This is not a homework; I need this for my unit tests. Sample input:

  • 0

This is not a homework; I need this for my unit tests.

Sample input: <rows><row><a>1234</a><b>Hello</b>...</row><row>...</rows>.

Sample output: <rows><row><a>0.0</a><b>0.0</b>...</row><row>...</rows>.

You may assume that the document starts with <rows> and that parent node has children named <row>. You do not know the name of nodes a, b, etc.

For extra credit: how to make this work with an arbitrary well-formed, “free-form” XML?

I have tried this with a regex 🙂 without luck. I could make it “non-greedy on the right”, but not on the left. Thanks for your help.

EDIT: Here is what I tried:

    private static string ReplaceValuesWithZeroes(string gridXml)
    {
        Assert.IsTrue(gridXml.StartsWith("<row>"), "Xml representation must start with '<row>'.");
        Assert.IsTrue(gridXml.EndsWith("</row>"), "Xml representation must end with '<row>'.");

        gridXml = "<deleteme>" + gridXml.Trim() + "</deleteme>"; // Fake parent.
        var xmlDoc = XDocument.Parse(gridXml);
        var descendants = xmlDoc.Root.Descendants("row");
        int rowCount = descendants.Count();
        for (int rowNumber = 0; rowNumber < rowCount; rowNumber++)
        {
            var row = descendants.ElementAt(0);
            Assert.AreEqual<string>(row.Value /* Does not work */, String.Empty, "There should be nothing between <row> and </row>!");
            Assert.AreEqual<string>(row.Name.ToString(), "row");

            var rowChildren = row.Descendants();
            foreach (var child in rowChildren)
            {
                child.Value = "0.0"; // Does not work.
            }
        }

        // Not the most efficient but still fast enough.
        return xmlDoc.ToString().Replace("<deleteme>", String.Empty).Replace("</deleteme>", String.Empty);
    }
  • 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-20T09:21:11+00:00Added an answer on May 20, 2026 at 9:21 am
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            foreach (XmlElement el in doc.SelectNodes("//*[not(*)]"))
                el.InnerText = "0.0";
            xml = doc.OuterXml;
    

    or to be more selective about non-empty text nodes:

            foreach (XmlText el in doc.SelectNodes("//text()[.!='']"))
                el.InnerText = "0.0";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all this is not homework, I'm in a desperate need for a
This is not homework, I need this for my program :) I ask this
This one is a case of not doing your homework.:-) Apart from dynamic loading
Disclaimer: This is for a homework assignment, but the question is not regarding the
This may not be the correct way to use controllers, but I did notice
This is homework, but I need a nudge. I can't find how to sort
This is not a homework problem, though it is a work problem. Where months
(Before anyone asks, this is not homework.) I have a set of workers with
This is not a homework, but new task assign by superior. To create a
This is not a homework. Visually it looks like a tree, but all leafs

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.