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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:17:38+00:00 2026-05-31T13:17:38+00:00

I am making a WPF that searches through an XML file pulling out restaurant

  • 0

I am making a WPF that searches through an XML file pulling out restaurant information. The XML is in this format:

    <FoodPhoneNumbers>
      <Restaurant Name="Pizza Place">
        <Type>Pizza</Type>
        <PhoneNumber>(123)-456-7890</PhoneNumber>
        <Hours>
          <Open>11:00am</Open>
          <Close>11:00pm</Close>
        </Hours>
      </Restaurant>
    </FoodPhoneNumbers>

I want to be able to add a new restaurant to the XML file. I have a textbox for the restaurant name, and type. Then three textboxes for the phone number. 4 comboboxes for the open hour, open minute, close hour, and close minute. I also have 2 listboxes for selecting AM or PM for the open and close times.

I assume I use XmlTextWriter, but I could not figure out how to add the text to a pre-existing XML file.

  • 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-31T13:17:38+00:00Added an answer on May 31, 2026 at 1:17 pm

    The simplest way isn’t to use XmlTextWriter – it’s just to load the whole into an in-memory representation, add the new element, then save. Obviously that’s not terribly efficient for large files, but it’s really simple if you can get away with it. For example, using XDocument:

    XDocument doc = XDocument.Load("test.xml");
    XElement restaurant = new XElement("Restaurant",
        new XAttribute("Name", "Frenchies"),
        new XElement("Type", "French"),
        new XElement("PhoneNumber", "555-12345678"),
        new XElement("Hours",
             new XElement("Open", "1:00pm"),
             new XElement("Close", "2:00pm")));
    doc.Root.Add(restaurant);
    doc.Save("test.xml");
    

    Or, better:

    XDocument doc = XDocument.Load("test.xml");
    Restaurant restaurant = ...; // Populate a Restaurant object
    
    // The Restaurant class could know how to serialize itself to an XElement
    XElement element = restaurant.ToXElement();  
    
    doc.Root.Add(element);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a WPF program that contains a TreeView. I am having a
I am making a WPF-application.I have a datagrid with a column header that contains
I made an WPF app that plays sounds using the MediaPlayer class. This works
I'm making a WPF application that is comprised of Screens (Presenter + View). I
I'm fleshing out a WPF business application in my head and one thing that
I'm making a simple WPF application with shapes that are drawn on a canvas.
So I have a check box that fires a command using WPF/MVVM this works
I'm making a MessageBox control in WPF using the MVVM pattern. This MessageBox will
I need to build a WPF control that looks somehow similar to this: alt
I'm making a Wpf Application. My problem is that I'm using a DataGrid to

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.