Avatar of Easwaran Paramasivam
Easwaran ParamasivamFlag for India asked on

Console application to manipulate XML in .NET using C#

Hi Experts,

 Please refer below sample xml.  I would like to develop a console applications in C# in a such a way that they solve below problems. Could you please suggest how to achieve? Thanks in advance!

1. Add or Update/Delete existing Person
Say for instance if user chooses Update option it should ask which Person he needs to update and what details should be updated (ex. Age value should be modified as 55

<PersonDetails>
   <Person>
     <Name>Easwar</Name>
     <Age>26</Age>
   </Person>
<Person>
     <Name>Baskar</Name>
     <Age>24</Age>
   </Person>
<PersonDetails>

Open in new window


2. For existing Person, if address details need to be added, it should add accordingly. The program should be generic in such a way that I could add qualification details later point as same as address.

<PersonDetails>
   <Person>
     <Name>Easwar</Name>
     <Age>26</Age>
      <Address>
           <Street>Gandhi nagar</Street>
            <City>Mumbai<City>
            <PinCode>4000234</PinCode>
      <Address>
   </Person>
<Person>
     <Name>Baskar</Name>
     <Age>24</Age>
   </Person>
<PersonDetails>

Open in new window

XMLC#.NET Programming

Avatar of undefined
Last Comment
Dmitry G

8/22/2022 - Mon
David Johnson, CD

first fix your xml the corrected version is below.. Garbage in, Garbage Out.
<?xml version="1.0" encoding="utf-8" ?>
<PersonDetails>
  <Person>
    <Name>Easwar</Name>
    <Age>26</Age>
    <Address>
      <Street>Gandhi nagar</Street>
      <City>
        Mumbai<City>
          <PinCode>4000234</PinCode>
          </Address>
   </Person>
  <Person>
    <Name>Baskar</Name>
    <Age>24</Age>
  </Person>
  </PersonDetails>

Open in new window

SOLUTION
Dmitry G

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Easwaran Paramasivam

This answers the first part of the question. Could you please provide the second query? Thanks!
Dmitry G

Honestly, I haven't got your second question. Could you please explain in more details what you want?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
Easwaran Paramasivam

Well. In the XML, say for instance a person XML contains some nodes exists already such as first name, last name. Assume that this is from a third party application output. I want to add an address node for a particular person as given in the sample in the question. Likewise I need to develop a dynamic program which should allow other nodes as well later such as qualification. Could you please assist?
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.