Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,963 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,530 people online right now. Registration is fast and FREE... Join Now!




Linq to XML updating a record

 
Reply to this topicStart new topic

Linq to XML updating a record, selecting and then updating a record in XML

DrakenKorin
19 May, 2008 - 12:41 AM
Post #1

New D.I.C Head
*

Joined: 19 Feb, 2008
Posts: 6


My Contributions
Hi,

Lately I've been teaching myself Linq, specifically Linq to XML, using whatever resources I can find on the interweb.

I'm having a hard time finding useful info on how to select a specific record from a xml file and then updating it.

This is how I created my XML document:

CODE


currentProject = new XDocument(
                        new XDeclaration("1", "utf-8", "yes"));

XElement Course = new XElement("Course",
                    new XElement("CourseName", courseNameXML),
                new XElement("CourseDesc", courseDescXML),
                new XElement("ReqToTrain", courseReqTrainXML),
                new XElement("CourseStatus", courseStatusXML));


and this is the resulting xml: (Well, not really, some of the contents of this XML file has been created earlier using similar code)

CODE
<Projects>

    <Project>
<ProjectName>TestProject 1</ProjectName>
<ProjectDesc>TestProject 1 Description</ProjectDesc>
<ProjectStart>2008/05/19 01:13:01 PM</ProjectStart>
<ProjectEnd>2008/08/21 01:13:17 PM</ProjectEnd>
</Project>

    <Course>
<CourseName>Test Course 1</CourseName>
<CourseDesc>Test Course 1 Description</CourseDesc>
<ReqToTrain>20</ReqToTrain>
</Course>

    <Course>
<CourseName>Test Course 2</CourseName>
<CourseDesc>Test Course 2 description</CourseDesc>
<ReqToTrain>10</ReqToTrain>
</Course>

    <Course>
<CourseName>Test Course 3</CourseName>
<CourseDesc>Test Course 3 Description</CourseDesc>
<ReqToTrain>5</ReqToTrain>
</Course>

    <Venue>
<VenueName>Test Venue 1</VenueName>
<VenueCap>20</VenueCap>
</Venue>

    <Venue>
<VenueName>Test Venue 2</VenueName>
<VenueCap>10</VenueCap>
</Venue>

    <Venue>
<VenueName>Test Venue 3</VenueName>
<VenueCap>5</VenueCap>
</Venue>
</Projects>


I'm having a hard time figuring out how to select a specific <course> node, and its corresponding <ReqToTrain> node.

Any help will be greatly appreciated!

This is for a training logistics app. Basically it allows you to setup various training courses, the number of people required to train and course duration, then matches those training courses to training venues. The app divides the number of people requiring training with the selected venue capacity and works out how many days you require to complete your training course. After everything is setup, you can export your training schedule to Outlook.

Help me with this one little issue, and I will gladly post this entire app and it's source code as a tutorial here on DIC

"Edit"
Oops! I forgot to add, that at this stage, the XML document does not exists anywhere on the local file system, it is currently only in memory, and only gets created when the user decides to save the current "project"

This post has been edited by DrakenKorin: 19 May, 2008 - 01:23 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:36AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month