Selecting nodes in xml, and comparing them to a directory
I know this has been asked many times before but i believe my situation is slightly different because of my node names, and sadly, they must remain, i cannot change them.
so, my issue is that I writing a program to check a directory and its subfolders (not files) against an xml tree. I have already implemented the reverse of checking the xml against the directory for missing folders, now i want to check for extra folders that arent part of the xml tree, and in order to do so i guessed that the selectsinglenode() would be the best way to go about it.
so my xml file looks like so....
Code:
<?xml version="1.0"?>
<XMLTreeView>
<Node name='.Drawing' />
<Node name=".Paint">
<Node name="EDR" />
<Node name="FDM" />
<Node name="ERG" />
<Node name="FTL" />
<Node name="MRG" />
<Node name="MOR" />
</Node>
<Node name=".Materials" />
<Node name=".WS" />
<Node name=".SJI" />
</XMLTreeView>
and heres what i have so far...
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
TextBox1.Text += " Folders not in indexed structure:" + ControlChars.NewLine + ControlChars.NewLine
For Each Dir As String In Directory.GetDirectories("C:\Users\Aaron\Documents\KTDStruct")
For Each Dir2 As String In Directory.GetDirectories(Dir)
CheckFolderAgainstIndex("C:\Users\Aaron\Documents\struct1.xml", Dir2)
Next
Next
End Sub
Private Sub CheckFolderAgainstIndex(ByVal XMLFilepath As String, dir As String)
Dim XMLDoc As New Xml.XmlDocument
Dim XMLNode As Xml.XmlNode
Dim folderName As String
Try
XMLDoc.Load(XMLFilepath)
Catch e As Exception
Throw New Exception(e.Message)
End Try
Dim subfolders() As String = Directory.GetDirectories(dir)
For Each folder In subfolders
folderName = folder.Split("\").Last
Try
XMLNode = XMLDoc.SelectSingleNode(folderName)
If XMLNode Is Nothing Then
TextBox1.Text += dir + "\" + folderName + ControlChars.NewLine
End If
Catch
TextBox1.Text += "error: " + dir + "\" + folderName + ControlChars.NewLine
End Try
Next
End Sub
the following is what comes out on textbox1:
Code:
Folders not in indexed structure:
error: C:\Users\Aaron\Documents\KTD\PersonABC\1234\.Drawing
error: C:\Users\Aaron\Documents\KTD\PersonABC\1234\.Paint
error: C:\Users\Aaron\Documents\KTD\PersonABC\1234\.QS
error: C:\Users\Aaron\Documents\KTD\PersonABC\1234\.SJI
C:\Users\Aaron\Documents\KTD\PersonABC\1234\faadfjadf
i added in the "faadfjadf" folder into the structure at random so that it would catch it, and it does, however...
if i change the .paint folder to just paint, and in the xml file as well, it doesnt report the error, but still says that the xml file doesnt have a node called paint :(
im just confused, im not worried about the subfolders at the moment, thats just a little recursion later.
heck, maybe im going about this all wrong anyways and someone has a better idea on comparing an xml to a directory structure