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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:39+00:00 2026-05-24T16:04:39+00:00

I just started using VS2010 and C#. I’m trying to create an app which

  • 0

I just started using VS2010 and C#.

I’m trying to create an app which takes values from two textboxes and adds it to an existing xml file.

eg.

Text Box 1       Text Box 2
----------       ----------
A                B
C                D
E                F

I want the resultant xml file to be like this.

<root>
 <element>
 <Entry1>A</Entry1>
 <Entry2>B</Entry2>
 </element>
</root>

and so on…

Can this be done using C# ??

I’m unable to add the entries alternatively i.e. Entry1 should contain Text Box 1 line #1 and Entry2 Text Box 2 line #1.

Any help would be appreciated.

Thanks

  • 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-24T16:04:39+00:00Added an answer on May 24, 2026 at 4:04 pm

    You need to split the string retrieved from the text box based on the new line like this:

    string[] lines = theText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
    

    Once you have values split for each text box, you can use System.xml.linq.xdocument class and loop through the values that you retrieve above.

    Something like this:

    XDocument srcTree = new XDocument(new XElement("Root",
        new XElement("entry1", "textbox value1")))
    

    You can retrieve a xml document using a linq query or save it in an xml file using the Save method of XDocument

    The below code will give you a string of XML data from the textboxes:

    private string createXmlTags(TextBox textBox1, TextBox textBox2)
        {
            string strXml = string.Empty;
            string[] text1Val = textBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string[] text2Val = textBox2.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            int count = 1;
            IList<XElement> testt = new List<XElement>();
            
            for (int i = 0; i < text1Val.Count(); i++)
            {
                testt.Add(new XElement("Entry" + count, text1Val[i]));
                while (!String.IsNullOrEmpty(text2Val[i]))
                {
                    count = count + 1;
                    testt.Add(new XElement("Entry"+count,text2Val[i]));
                    break;
                }
                count = count + 1;
            }
            foreach (var xElement in testt)
            {
                strXml += xElement.ToString();
            }
            return strXml;
        }
    

    You can then insert the code to an existing xml document. Follow: How can I build XML in C#? and How to change XML Attribute

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

Sidebar

Related Questions

I've just started using VS2010. I've got a largish solution that migrated successfully from
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I've just started using a VS2010 database project to manage the release of an
Just started using log4net and trying to get my head around the config and
I just started using resharper and I am trying to learn all the hotkeys
Just started using App Engine's webapp framework, but I can't figure out what's wrong
I just started using Matplotlib and am trying to change the color of the
I've just started using WCF here at work and am trying to add a
I just started using Datamapper. I am trying to update an object. I get
Have just started using Google Chrome , and noticed in parts of our site,

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.