-<Jobs> -<Job> <JobName>a</JobName> <Source>C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg</Source> <Source>C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg</Source> <Destination>C:\Users\Public\Pictures\Sample Pictures\a.zip</Destination> <Timestamp>11/26/2012 6:18:00 PM</Timestamp> </Job> -<Job> <JobName>b</JobName> <Source>C:\Users\Public\Pictures\demo photo\1 - Copy.JPG</Source> <Source>C:\Users\Public\Pictures\demo photo\1.JPG</Source> <Destination>C:\Users\Public\Pictures\demo photo\b.zip</Destination> <Timestamp>11/26/2012 6:18:19 PM</Timestamp> </Job> </Jobs>
This is the XMl file i'm reading. Right now, the code (found below) wil read each node and output it to the console. It will also zip ALL the files found within the 'source' nodes and create two zips (in both 'destination' node). However, i want each 'job' to be seperate. I want "Job A" zip the files located in that job (Lighthouse.jpg & penguins.jpg) and store the zip in the respective destination. But my problem comes at this point. The program zips all the 'source' nodes together and makes two seperate zips with all the files contained within. Check my code..i'm sure it's something simple.
Sub main()
Dim doc As New System.Xml.XmlDocument
doc.Load("C:\users\matt taylor\desktop\backup\backup.xml")
Dim JobNodes As XmlNodeList
Dim JobNode As XmlNode
Dim baseDataNodes As XmlNodeList
JobNodes = doc.GetElementsByTagName("Job")
For Each jobNode In JobNodes
baseDataNodes = JobNode.ChildNodes()
For Each baseDataNode As XmlElement In baseDataNodes
Dim Source = baseDataNode.SelectNodes("descendant::Source")
Dim Destin = baseDataNode.SelectNodes("descendant::Destination")
Using zip As New ZipFile()
For Each item As System.Xml.XmlNode In Source
zip.AddFile(item.InnerText, "Archive_" & DateString)
Next
For Each item As System.Xml.XmlNode In Destin
zip.Save(item.InnerText)
Next
End Using
Console.Write(vbCrLf)
Console.Write(baseDataNode.Name & ": " & baseDataNode.InnerText)
Next
Console.Write(vbCrLf)
Console.Write(vbCrLf)
Next
Console.Read()
End Sub

New Topic/Question
Reply



MultiQuote






|