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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:52:08+00:00 2026-06-18T15:52:08+00:00

I am appending to an existing xml file: The code is below: I am

  • 0

I am appending to an existing xml file: The code is below: I am using C# .net 4.5 VS 2012 and creating a WPF application.

How could I append this say 30 times and only change D100 attribute number to 2,3,4,5 etc?
The other values are the same!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace AppendX
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\Temp.xml");

            XmlNamespaceManager namespaces = new XmlNamespaceManager(doc.NameTable);
            namespaces.AddNamespace("flp", "http://www.w3.org/2001/flp");



            XmlNode nextNode = doc.SelectSingleNode("/flp:Tab/flp:Designs", namespaces);

            XmlElement D100 = doc.CreateElement("flp", "D100", "http://www.w3.org/2001/flp");
            D100.SetAttribute("Number", "2");

            XmlElement Code = doc.CreateElement("flp", "Code", "http://www.w3.org/2001/flp");
            Code.InnerText = "B";
            D100.AppendChild(Code);

            XmlElement Documented = doc.CreateElement("flp", "Documented", "http://www.w3.org/2001/flp");
            Documented.InnerText = "false";
            D100.AppendChild(Documented);

            nextNode.AppendChild(D100);

            doc.Save("test1.xml");



        }
    }
}

Here is the sample xml I am using, sorry I meant to put this up!

<flp:Tab xmlns:flp="http://www.w3.org/2001/flp"   Title="Testing">
  <flp:Form Number="0" id="1005" />
  <flp:Rev Time="2013-01-21T15:08:00">
    <flp:Author Name="Brad" Aid="15" />
  </flp:Rev>
  <flp:Designs Id="D100">
    <flp:D100 Number="1">
      <flp:Code>A</flp:Code>
      <flp:Documented>true</flp:Documented>
    </flp:D100>
  </flp:Designs>
</flp:Tab>
  • 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-06-18T15:52:09+00:00Added an answer on June 18, 2026 at 3:52 pm

    Create a separate private function that would handle the creation of the document element, given the parameters. ex:

    private xmlelement dothework(string param1, string param2){
    
        'do all necessary work to set up the element in here and then return it
    
    }
    

    I would separate the work like this, create a different function for each section of work, so that eventually you can just loop through and append each to the document.

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

Sidebar

Related Questions

When appending to a file using Windows batch commands, how to append immediately after
i've trying to perform appending to an existing file from resource file using the
I was having trouble appending object file in my program. I found this SO
I am appending new data - $('#posts').append(data); But I want this new data to
I was wondering if anyone could take a look at this code and help
I am appending div in existing div and then one more div into append
I am trying to create a new XML file from an exisiting one using
Currently, im having this for appending data to my items file: $xmldoc = new
I am writing an application which needs to add nodes to an existing XML
I am having some luck when i try appending some text to an existing

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.