473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Writing multiple entires to an XML

maylortaylor
72 64KB
I am trying to get my XML file to add more entries. Right now, when i run my program it makes the xml below. But when i run the program a second time it replaces the XML with the new information.

I want to be able multiple 'jobs' or entries.

Expand|Select|Wrap|Line Numbers
  1. <Job> <JobName>e</JobName> <Source>C:\Users\Public\Pictures\Sample Pictures\Desert.jpg</Source> <Destination>C:\Users\Public\Pictures\Sample Pictures\a.zip</Destination> <Timestamp>11/21/2012 12:12:04 PM</Timestamp> </Job>
Example: First time i run the program, i name the job "a". After program finishes and XML is written i want to be able to then run the program again with a job named "b" and have it added to the xml file. This way i can search for specific jobs.

Below is the code where I write the XML code. I am thinking my issue is here and could be solved with a "for each" loop..but i'm clueless.

Expand|Select|Wrap|Line Numbers
  1. Dim filesEnum2 As IEnumerator
  2.         filesEnum2 = OpenFileDialog1.FileNames.GetEnumerator()
  3.  
  4.         With xmlwrt
  5.             .WriteStartDocument()
  6.             .WriteComment("XML Backup.")
  7.             .WriteStartElement("Job")
  8.  
  9.             Dim jName As String = JobName.Text.ToString
  10.             .WriteElementString("JobName", jName.ToString)
  11.  
  12.  
  13.             While filesEnum2.MoveNext
  14.                 .WriteStartElement("Source")
  15.                 .WriteString(filesEnum2.Current)
  16.                 .WriteEndElement()
  17.             End While
  18.  
Nov 21 '12 #1
1 1420
maylortaylor
72 64KB
OK, i've gotten a lot of the issues sorted using the AppendChild() method. Now my XML is looking like this

Expand|Select|Wrap|Line Numbers
  1. <Jobs> 
  2. -<Job> 
  3. <JobName>a</JobName> 
  4. <Source>C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg</Source> <Source>C:\Users\Public\Pictures\Sample Pictures\Desert.jpg</Source> 
  5. <Destination>C:\Users\Public\Pictures\Sample Pictures\a.zip</Destination> 
  6. <Timestamp>11/21/2012 4:06:14 PM</Timestamp> </Job> 
  7.  
  8. -<Job> <JobName>e</JobName> 
  9. <Source>C:\Users\Matt Taylor\Pictures\Alex-Grey-Vision-Crystal.jpg</Source> 
  10. <Destination>C:\Users\Matt Taylor\Pictures\e.zip</Destination> 
  11. <Timestamp>11/21/2012 4:21:37 PM</Timestamp> </Job> </Jobs>
  12.  
However, now my issues is that I am only getting a single file as my source even though i have multiple files selected. I know this is a simple solution, my brain is just fried.

Below is the code for calling the appendchild methods. In case that helps.

Expand|Select|Wrap|Line Numbers
  1. Dim doc As New XmlDocument()
  2.             doc.Load("C:\Users\Matt Taylor\Desktop\Backup\Backup.xml")
  3. Dim jName As XmlElement = doc.CreateElement("JobName")
  4. Dim jsource As XmlElement = doc.CreateElement("Source")
  5. job.AppendChild(jName)
  6. job.AppendChild(jsource)
  7. doc.DocumentElement.AppendChild(job)
  8.  
  9. jName.Innertext = jobName.text.tostring
  10.  
  11. While filesEnum3.movenext
  12. jsource.InnerText = filesEnum3.Current
  13. jsource.WriteTo(jsource.InnerText)
  14. End While
  15.  
  16.  

I'm not too hot with VB, so I'm not sure if the "filesEnum3.movenext" and ".current" lines are useful. This is the method i used to have the info print to the XML in the first place..so i figured i could just copy it and it would work. apparently not >,<
Nov 21 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: NotGiven | last post by:
I have used dreamweaver to do a lot of php "programming" but now I need to write a real php function. I have a hosted mysql database that I need to export to MS Access. I can't use myODBC to do...
5
by: Dave Opstad | last post by:
File this one under "enhancement request" I guess, but it would sure be nice. I wrote this line the other day, thinking it would just work: x = struct.pack(">HhhhhhhHHHL", i, *bounds, *b, *b,...
2
by: caro | last post by:
Hi I am trying to write two Select * statements to the same text file using bcp (from a stored procedure). But cannot find a way of appending to a file using bcp. Does anyone know if this...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
1
by: method | last post by:
Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only...
2
by: amir | last post by:
How can I filter my database in Multiple way, I mean that I wana to filter st. like this: sm* *th* *er Please Help me on this matter Amir
1
by: homerzzz | last post by:
I want to save links to a cookie. So far I can save one link by: var value=document.getElementById("link1").href; document.cookie=cookiename + "=" + escape(value); If I want to save several...
1
by: patrick.waldo | last post by:
Hi all, I was just curious if there was a built-in or a more efficient way to do take multiple rows of information and write them into excel using pyExcelerator. This is how I resolved the...
2
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random();...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.