-
November 29th, 2012, 11:21 AM
#1
Issue zipping files from XML
So I have an XML that looks like this...
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--XML Backup.-->
-<Jobs>
-<Job>
<JobName>a</JobName>
<Source>C:\Users\Public\Pictures\Samplepictures\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 i want each Parent Node labeled "Job" to be zipped. So the first zip would be "a.zip", with "tulips.jpg","lighthouse.jpg",and "penguins.jpg" 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.
The code i have now is as follows.
Code:
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
Dim Source = baseDataNode.SelectNodes("descendant::Source")
Dim Destin = baseDataNode.SelectNodes("descendant::Destination")
Using zip As New ZipFile()
For Each item As System.Xml.XmlElement In Source
zip.AddFile(item.InnerText, "Archive_" & DateString)
Next
For Each item As System.Xml.XmlElement 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
Also, i'm curious if the "descendant::" is necessary ..if so, what does it do?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|