Hi Ian, I might have misunderstood what you're after, but doesn't ` ParkTestVideoXMLFile.Root.Add(/* content */)` work to solve this problem?
Cheers. James. From: [email protected] [mailto:[email protected]] On Behalf Of Ian Thomas Sent: Monday, 19 November 2012 11:39 To: [email protected] Subject: LINQ to XML question I have been using LINQ to XML in VB.NET (it's more useful to me than C# because of XML literals), but in a very naïve and simple way. Now, I want to make my code more flexible. Currently (ParkTestVideoXMLFile is of type XDocument) I do this - ParkTestVideoXMLFile = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <TestResults> <TestResult personid="0" code=<%= CurrentPatientCode %> clinicianid="4" requestid="0" datetime=<%= CurrentPatient_StartTime %>> <Test id=<%= CurrentTestName %> datetime=<%= CurrentTest_StartTime %>></Test> <Data type="Videofile" values=<%= sSaveFileName & sVideoExt %>></Data> </TestResult> </TestResults> which creates something like this - <?xml version="1.0" encoding="utf-8" standalone="yes"?> <TestResults> <TestResult personid="0" code="1235" clinicianid="4" requestid="0" datetime="2012-11-09T19:10:39.5477585+08:00"> <Test id="ProSupLeft" datetime="2012-11-09T19:10:48.1862526+08:00"></Test> <Data type="Videofile" values="VR_1235_ProSupLeft_2012-11-09_191045.WMV"></Data> </TestResult> <!-- I would like to add many additional TestResult data here --> </TestResults> After writing the file to disk (ParkTestVideoXMLFile.Save(CurrentXMLFile, SaveOptions.None)) I would like to insert additional TestResult data at the location highlighted, at some future time. Users may terminate the program at any time, sometimes electing not to save the most recent test results. What would be your suggestions for doing this? Or, should I just retain each Test's variables in arrays and construct the whole XDocument at the time of exit? I guess the simple question is: how do I insert? Do I have to traverse the XML tree, and is this more complicated than simply maintaining a few arrays? The memory load for this data is tiny. ________________________________ Ian Thomas Victoria Park, Western Australia
