So I have an XML that looks like this...
And i want each Parent Node labeled "Job" to be zipped. So the first zip would be "a.zip", with "tulips.jpg","l ighthouse.jpg", and "penguins.j pg" inside - located at the destination.
And the second zip would be "b.zip" with the respective files.
right now, i am getting "a.zip" and "b.zip" in the right destinations - BUT each zip contains all the files.
Code:
<?xml version="1.0" encoding="UTF-8"?> <!--XML Backup.--> -<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> <Source>C:\Users\Public\Pictures\Sample Pictures\Tulips.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> <Source>C:\Users\Public\Pictures\demo photo\2 - Copy.JPG</Source> <Destination>C:\Users\Public\Pictures\demo photo\b.zip</Destination> <Timestamp>11/26/2012 6:18:19 PM</Timestamp> </Job> </Jobs>
And the second zip would be "b.zip" with the respective files.
right now, i am getting "a.zip" and "b.zip" in the right destinations - BUT each zip contains all the files.
Code:
Dim doc As New System.Xml.XmlDocument
doc.Load("C:\users\matt taylor\desktop\backup\backup.xml")
Dim nSource = doc.GetElementsByTagName("Source")
Dim nDestin = doc.GetElementsByTagName("Destination")
Dim JobNodes As XmlNodeList
Dim JobNode As XmlNode
Dim baseDataNodes As XmlNodeList
Dim bFirstInRow As Boolean
JobNodes = doc.GetElementsByTagName("Job")
For Each jobNode In JobNodes
baseDataNodes = JobNode.ChildNodes
bFirstInRow = True
For Each baseDataNode As XmlNode In baseDataNodes
Using zip As New ZipFile()
For Each item As System.Xml.XmlElement In nSource
zip.AddFile(item.InnerText, "Archive_" & DateString)
Next
For Each item As System.Xml.XmlElement In nDestin
zip.Save(item.InnerText)
Next
End Using
Console.Write(vbCrLf)
Console.Write(baseDataNode.Name & ": " & baseDataNode.InnerText)
Next
Console.Write(vbCrLf)
Console.Write(vbCrLf)
Next
Comment